求助 设计用户登录 密码没错 老是显示密码错误
Private Sub cmdOK_Click()txtUserName.Text = Trim(txtUserName.Text)
If txtUserName.Text = "" Then
MsgBox " 请输入用户名!"
Exit Sub
End If
txtPassword.Text = Trim(txtPassword.Text)
If txtPassword.Text = "" Then
MsgBox " 请输入密码!"
Exit Sub
End If
Dim msg, style, title, response
Dim Conn As New ADODB.Connection '声明并实例化连接数据库对象 -- 用来连接数据库文件,并对数据库以及数据表的操作
Dim Rst As New ADODB.Recordset '声明并实例化数据记录集对象 -- 用来返回数据记录集,并对记录的操作
'执行 ADODB.Connection对象的Open方法,完成数据库的连接
Conn.Open SQLConnecTionString1
'执行 ADODB.Recordset对象的Open方法,获得记录集
Rst.Open "Select * From 用户 Where 用户名='" & txtUserName.Text & "'", Conn, adOpenKeyset, adLockPessimistic
If Not (Rst.RecordCount >= 1) Then
MsgBox "数据表记录为0!"
End
End If
If Not (Rst.EOF And Rst.BOF) Then
'检查正确的密码
If Rst.Fields("密码") = txtPassword.Text Then
Unload Me
Form1.Show
Else
msg = "错误的登录密码!" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
style = vbRetryCancel + vbExclamation + vbDefaultButton1
title = "提示"
response = MsgBox(msg, style, title)
If response = vbRetry Then
Exit Sub
ElseIf response = vbCancel Then
End
End If
End If
Else
msg = "错误的用户名!" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
style = vbRetryCancel + vbExclamation + vbDefaultButton1
title = "提示"
response = MsgBox(msg, style, title)
If response = vbRetry Then
Exit Sub
ElseIf response = vbCancel Then
End
End If
End If
End Sub