我用VB做了一个登陆界面。。。连接SQL数据库,如何判断用户名密码,以下是代码,不知道哪里错了,帮改改
Dim strSQL As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cmdEnter_Click()
If txtUser.Text = "" Then
MsgBox "请您输入用户名"
txtUser.SetFocus
Exit Sub
End If
If txtPwd.Text = "" Then
MsgBox "请您输入密码"
txtPwd.SetFocus
Exit Sub
End If
cn.ConnectionString = "driver={sql server};server=(local);database=userman;uid=sa;pwd=sa"
cn.Open
cn.CursorLocation = adUseClient
strSQL = "select * from users where userName='" & txtUser.Text & " ' and userPwd= ' " & txtPwd.Text & " '"
rs.Open strSQL, cn, adOpenStatic, adLockReadOnly
If rs.RecordCount = 0 Then
MsgBox "用户名不正确"
Else
If rs.Fields(0).Value = txtPwd.Text Then
MsgBox "登录成功"
Else
MsgBox "密码错误"
End If
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub