Private Sub cmdok_Click()
'ToDo: 创建测试密码是否正确
'检查正确密码
Dim pwdtext As String
Dim user As String
Dim userquery As String
user = txtusername.Text
pwdtext = txtpassword.Text
Set dbm = New Connection
dbm.CursorLocation = adUseClient
dbm.Open "PROVIDER=MSDASQL;dsn=kaoqin1;uid=;pwd=;"
Set adoPrimaryRS = New Recordset
userquery = "select pass from userinfo where username='" & user & "'"
adoPrimaryRS.Open userquery, dbm, adOpenStatic, adLockOptimistic
If Not (adoPrimaryRS.BOF And adoPrimaryRS.EOF) Then
'此用户存在
If adoPrimaryRS!pass = pwdtext Then
OK = True
Unload Me
Else: MsgBox "密码错误,再试一次!", , "登录"
txtpassword.SetFocus
txtpassword.SelStart = 0
txtpassword.SelLength = Len(txtpassword.Text)
End If
Uname = user
adoPrimaryRS.Close
Set adoPrimaryRS = Nothing
dbm.Close
Set dbm = Nothing
txtpassword.Text = ""
Else: MsgBox "无此用户,重试!", , "警告"
txtusername.SetFocus
txtusername.SelStart = 0
txtusername.SelLength = Len(txtpassword.Text)
End If