下面是登录窗口识别用户名和密码
运行时显示"不可识别的数据库格式'这里是.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
运行时显示"不可识别的数据库格式'这里是.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
Private Sub Form_Load() '系统初始化,加载数据库
Dim Connectionstring As String, UID As String, PWD As String
Dim conn As New ADODB.Connection
conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"
conn.Open
End SubPrivate Sub CommandButton1_Click()
Dim SQL As String
Dim rs_Login As New ADODB.Recordset
Dim UID As String, PWD As String
If Trim(Text1.Text) = "" Then '判断输入的用户名是否为空
MsgBox "请输入用户名", vbOKOnly + vbExclamation
Text1.Text = ""
Text1.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, 1, 3 '调试错误指向这行,说连接无法执
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
UID = Text1.Text
PWD = 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
userid从哪看啊,谢谢
---------------------------------------------------------------------
你用的是sql server2000数据库。
数据库本身就用这个"sa"作为userid .
-----------------------------
你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
----
如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
----------------------------------
你再试一试
---------------------------------------------------------------------
你用的是sql server2000数据库。
数据库本身就用这个"sa"作为userid .
-----------------------------
你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
----
如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
----------------------------------
你再试一试
---------------------------------------------------------------------
你用的是sql server2000数据库。
数据库本身就用这个"sa"作为userid .
-----------------------------
你打开企业管理器,然后在local上右键,--->属性-->安全性--->选sql server and windows
----
如果你在安装sql server的时候没有设置密码的话,你的密码就为"".
----------------------------------
你再试一试
conn.Connectionstring = "driver={SQL Server};server=Lenovo-671a05ae;UID=;PWD=;Database=student"如果我按楼上有的朋友说的把UID=改成UID=sa,一运行就直接说用户'sa'登录失败
这是怎么回事啊?还有这个database后面是不是写我见的student数据库名字啊,谢谢各位的解答!!