做了一个登录框 提示:不可识别的数据库格式。求解
我做了张数据库的表,不知错在那里,请指教,我做了一个带登录框,有用户名和密码要用到这个数据库,总是提示:“不可识别的数据库格式”。请教高手我数据库格式错在那儿?
test.rar
(10.44 KB)
Private Sub Command1_Click()
Dim sql As String
Dim conn As New ADODB.Connection
Dim rs_login As New ADODB.Recordset
If Trim(Text1.Text) = "" Then '检测用户名正确与否
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1.SetFocus
Else
sql = "select * from Test where test_info = '" & Text1.Text & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "用户名不存在,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text1 = ""
Text1.SetFocus
Else '检测密码正确与否
If Trim(rs_login.Fields(1)) = Trim(Text2) Then
rs_login.Close
Unload Me
Form2.Show
Else
MsgBox "密码错误,请重新输入!", vbOKOnly + vbExclamation, "错误"
Text2.SetFocus
End If
End If
End If
End Sub
Private Sub Command2_Click()
MsgBox "您已成功退出!", vbOKOnly + vbExclamation, "提示"
Unload Me
End Sub
Private Sub Form_Load() '此段代码的主要作用是当窗体打开时就连接数据库
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "E:\Test.mdb;Persist Security Info=False" '将Data Source 处的路径改为你本机数据库所在路径即可
conn.Open connectionstring
End Sub