用户输入数据然后与数据库中的数据进行比对,如果正确就登录否则提示
下面一段代码总是说from语句有错误,请高手看一下rs_Login.Open是否用错,
实在不知道错误在哪?请赐教
Option ExplicitPublic Conn As New ADODB.ConnectionPrivate Sub Command1_Click()
Dim SQL As String
Dim rs_Login As New ADODB.Recordset
If Trim(txtuser.Text) = "" Then '判断输入的用户名是否为空
MsgBox "请输入用户名", vbOKOnly + vbExclamation
txtuser.Text = ""
txtuser.SetFocus
ElseIf txtpwd.Text = "" Then
MsgBox "请输入密码", vbOKOnly + vbExclamation
txtpwd.Text = ""
txtpwd.SetFocus
Else
SQL = "select * from user where id='" & txtuser.Text & "'"
rs_Login.Open SQL, Conn, adOpenKeyset, adLockPessimistic
If rs_Login.EOF = True Then
MsgBox "对不起,没有这个用户", vbOKOnly + vbExclamation
txtuser.Text = ""
txtuser.SetFocus
rs_Login.Close
Else '检验密码是否正确
If rs_Login.Fields(1) = txtpwd.Text Then
rs_Login.Close
Unload Me
FrmLoading.Show
Exit Sub
Else
MsgBox "密码错误,请您重输", vbOKOnly + vbExclamation
txtpwd.Text = ""
txtpwd.SetFocus
rs_Login.Close
End If
End If
End IfEnd SubPrivate Sub Form_Load()
Dim Connectionstring As StringConnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\测试.mdb"
Conn.Open Connectionstring
End Sub