vb sql登陆窗口错误,提示实时错误3709
PrivateSubForm1Load()'此段代码的主要作用是当窗体打开时就连接数据库DimconnAsNewADODB.ConnectionDimconnection...
Private Sub Form1Load()
'此段代码的主要作用是当窗体打开时就
连接数据库
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=SQLOLEDB.1;User ID=sa;password=; Data Source=192.168.1.9 ;InitialCatalog=Test"
'User ID代表本机sql的登陆帐号,password是密码,Data Source代表数据源,在本例中,你还可将 127.0.0.1改为(local)或者你的sql服务器名称,IntitialCatalog就是你要连接的数据库名称
conn.Open connectionstring
End Sub
'接着双击“确定”同样的,输入如下代码:
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
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
这个代码提示出错,提示实时错误3709,大侠帮看看,谢谢 展开
'此段代码的主要作用是当窗体打开时就
连接数据库
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=SQLOLEDB.1;User ID=sa;password=; Data Source=192.168.1.9 ;InitialCatalog=Test"
'User ID代表本机sql的登陆帐号,password是密码,Data Source代表数据源,在本例中,你还可将 127.0.0.1改为(local)或者你的sql服务器名称,IntitialCatalog就是你要连接的数据库名称
conn.Open connectionstring
End Sub
'接着双击“确定”同样的,输入如下代码:
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
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
这个代码提示出错,提示实时错误3709,大侠帮看看,谢谢 展开
2个回答
展开全部
把
Private Sub Command1_Click()
Dim sql As String
Dim conn As New ADODB.Connection
中的
Dim conn As New ADODB.Connection
去掉即可
Private Sub Command1_Click()
Dim sql As String
Dim conn As New ADODB.Connection
中的
Dim conn As New ADODB.Connection
去掉即可
更多追问追答
追问
哥们,我把经去了,可是又提示 参数类型不正确,或不在接受的范围之内
追答
那就是新的问题,老的问题已经解决
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
conn定义成全局变量,因其在多个过程中使用
追问
能详细点吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询