我先把我的连接数据库和查询代码写出来,供你们参考,多谢大家了
Dim rs As adodb.Recordset
Dim dcn As New adodb.Connection
dcn.CursorLocation = adUseClient
dcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb;Persist Security Info=False"
If txtUserName.Text = "" Then
MsgBox ("请填入登录名")
Else
Set rs = New adodb.Recordset
rs.Open "select * from userlist where user ='" & txtUserName.Text & "'", dcn, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox ("登录名不存在")
txtUserName.SetFocus
Else
If rs!Password <> txtPassword.Text Then
MsgBox ("密码错误")
txtPassword.SetFocus
Else
Form2.Show
Unload Me
End If
End If
End If
Dim rs As adodb.Recordset
Dim dcn As New adodb.Connection
dcn.CursorLocation = adUseClient
dcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb;Persist Security Info=False"
If txtUserName.Text = "" Then
MsgBox ("请填入登录名")
Else
Set rs = New adodb.Recordset
rs.Open "select * from userlist where user ='" & txtUserName.Text & "'", dcn, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox ("登录名不存在")
txtUserName.SetFocus
Else
If rs!Password <> txtPassword.Text Then
MsgBox ("密码错误")
txtPassword.SetFocus
Else
Form2.Show
Unload Me
End If
End If
End If
Dim dcn As New adodb.Connection
dcn.CursorLocation = adUseClient
dcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb;Persist Security Info=False"
If txtUserName.Text = "" Then
MsgBox ("请填入登录名")
Else
Set rs = New adodb.Recordset
rs.Open "select * from userlist where user ='" & txtUserName.Text & "'", dcn, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox ("登录名不存在")
txtUserName.SetFocus
Else
If rs!Password <> txtPassword.Text Then
MsgBox ("密码错误")
txtPassword.SetFocus
Else
Form2.Show
Unload Me
exit sub'--------------------加一句
End If
End If
End If
你定义ado了没有啊