请各位看看,为什么这个错了,谢谢,很急啊
下面是登录窗口识别用户名和密码
运行时显示 "不可识别的数据库格式 '这里是.mdf文件的路径 ' "错误,点调试就指向下面第九行 "conn.open conectionstring "
Option Explicit
Public conn As New ADODB.Connection '标记连接对象
Private Sub Form_Load() '系统初始化,加载数据库
Dim Connectionstring As String
Dim conn As New ADODB.Connection
Connectionstring = "provider=Microsoft.Jet.oledb.4.0; " & _
"Data Source= " & App.Path & "\Student_Data.mdf "
conn.Open Connectionstring
End Sub
Private Sub CommandButton1_Click()
Dim SQL As String
Dim rs_Login As New ADODB.Recordset
If Trim(Text1.Text) = " " Then '判断输入的用户名是否为空
MsgBox "请输入用户名 ", vbOKOnly + vbExclamation
Text1.Text = " "
txtuser.SetFocus
ElseIf Text2.Text = " " Then
MsgBox "请输入密码 ", vbOKOnly + vbExclamation
Text2.Text = " "
Text2.SetFocus
Else
SQL = "select * from basic_information where studentid= ' " & Text1.Text & " ' "
rs_Login.Open SQL, conn, adOpenKeyset, adLockPessimistic
If rs_Login.EOF = True Then
MsgBox "对不起,没有这个用户 ", vbOKOnly + vbExclamation
Text1.Text = " "
Text1.SetFocus
rs_Login.Close
Else '检验密码是否正确
If rs_Login.Fields(1) = Text2.Text Then
UserID = Text1.Text
UserPow = rs_Login.Fields(2)
rs_Login.Close
Unload Me
Main.Show
Exit Sub
Else
MsgBox "密码错误,请您重输 ", vbOKOnly + vbExclamation
Text1.Text = " "
Text1.SetFocus
rs_Login.Close
End If
End If
End If
End Sub
Private Sub txtpwd_KeyPress(KeyAscii As Integer) '敲回车直接登陆
If KeyAscii = 13 Then CommandButton1_Click
End Sub
[解决办法]
conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student "
---------------------------------
你用的是sql server2000数据库。
数据库本身就用这个 "sa "作为userid .
-----------------------------
你打开企业管理器,然后在local上右键,---> 属性--> 安全性---> 选sql server and windows
----
如果你在安装sql server的时候没有设置密码的话,你的密码就为 " ".
----------------------------------
你再试一试