用VB做好一个程序,怎么调用ACCESS里面的数据 ?
展开全部
'引用:Microsoft ActiveX Data Objects 2.8 Library
'引用:C:\Program Files\Common Files\System\ado\msado15.dll
Private Sub cmdOK_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\StuScore.mdb;"
cn.Open
Dim strSQL As String
strSQL = "SELECT * FROM [user] where usern='" & txtUserName.Text & "' and password='" & txtPassword.Text & "'"
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
'Set rs = cn.Execute(strSQL)
If rs.BOF And rs.EOF Then
MsgBox "用户名或者密码错误!", vbCritical + vbOKOnly
Else
MsgBox "登录成功!", vbInformation + vbOKOnly
' 在此处书写登录成功后要做的操作代码
End If
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
'引用:C:\Program Files\Common Files\System\ado\msado15.dll
Private Sub cmdOK_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\StuScore.mdb;"
cn.Open
Dim strSQL As String
strSQL = "SELECT * FROM [user] where usern='" & txtUserName.Text & "' and password='" & txtPassword.Text & "'"
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
'Set rs = cn.Execute(strSQL)
If rs.BOF And rs.EOF Then
MsgBox "用户名或者密码错误!", vbCritical + vbOKOnly
Else
MsgBox "登录成功!", vbInformation + vbOKOnly
' 在此处书写登录成功后要做的操作代码
End If
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询