Dim rs As New ADODB.Recordset
dim cnn As New ADODB.Connection
Private Sub Command1_Click()
Dim strsql As String
Set rs = Nothing
Set cnn = Nothing
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\用户表.mdb;Persist Security Info=False"
cnn.Open
If Text1.Text = "" Then
MsgBox "请输入用户名!", vbCritical + vbOKOnly, "提示"
Text1.SetFocus
End If
strsql = "select*from users where username='" & Trim(Text1.Text) & "'"
rs.CursorLocation = adUseClient
rs.Open strsql, cnn, adOpenStatic, adLockOptimistic
If Text2.Text = rs.Fields("password") Then
MDIForm1.Show
Unload Me
Else
MsgBox ("用户名或者密码不正确!"), vbCritical + vbOKOnly, "提示"
End If
End Sub
够详细了吧,呵呵,给分吧
通过用户名在数据库中查找这个用户名相对应的密码,把密码提取出来,与界面上输入的密码进行比较~Yes的话继续执行代码,No的话就提示信息,然后中止程序。