VB6.0编写系统登录代码时遇到“实时错误3021”
请各位高手帮我一下,这段代码要怎么改,详细点,谢谢!
Option Explicit
Public conn As New ADODB.Connection
Public Userid As String
Dim cs As Integer '登录次数
Dim pwd As String
Dim rsUser As ADODB.Recordset
Private Sub Combo1_Click()
Dim sql As String
Set rsUser = New ADODB.Recordset
If rsUser.State = 1 Then rsUser.Close
sql = "select Userpwd from Userinfo where Userid='combo1.text'"
rsUser.Open sql, conn, adOpenStatic, adLockPessimistic
Text1.SetFocus
pwd = Trim(rsUser.Fields("Userpwd"))
调试时,这句标记为黄色!
End Sub
Private Sub Command1_Click()
If Combo1.Text = "" Then
MsgBox "请选择用户名!", , "登录"
Combo1.SetFocus
Exit Sub
End If
If Text1.Text = "" Then
MsgBox "请输入密码!", , "登录"
Text1.SetFocus
Exit Sub
End If
If Text1.Text = pwd Then
Userid = Combo1.Text
Me.Hide
Form2.Show
Else
MsgBox "密码无效,请重试!", , "登录"
Text1.SetFocus
cs = cs + 1
If cs = 3 Then
Unload Me
End If
End If
End Sub
Private Sub Form_Load()
Dim sql As String
Set rsUser = New ADODB.Recordset
conn.ConnectionString = "provider=Microsoft.jet.oledb.4.0;data source=human resource.mdb"
conn.Open
sql = "select Userid from Userinfo"
rsUser.Open sql, conn, adOpenDynamic, adLockPessimistic
Combo1.Clear
Do Until rsUser.EOF
Combo1.AddItem rsUser.Fields("Userid")
rsUser.MoveNext
Loop
cs = 0
End Sub
[解决办法]
- VB code
sql = "select Userpwd from Userinfo where Userid='"& combo1.text &"'"rsUser.Open sql, conn, adOpenStatic, adLockPessimisticif rsUser.recordcount>0 then Text1.SetFocus if not isnull(rsUser.fields("Userpwd")) then pwd = Trim(rsUser.Fields("Userpwd")) end ifend if