用VB编写一个管理软件!要求输入用户名和密码才能登陆.怎样让他与后台的access数据库核对用户名和密码呢?
2个回答
展开全部
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
够详细了吧,呵呵,给分吧
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
够详细了吧,呵呵,给分吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询