一段VB代码,一直提示“VB中连接无法用于执行此操作,在此上下文中它可能已经被关闭”
这是代码:PrivateSubCommand1_Click()DimsqlAsStringDimconnAsNewADODB.ConnectionDimrs_loginA...
这是代码:
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
这是错误行:sql = "select * from Test where test_info = '" & Text1.Text & "'" 展开
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
这是错误行:sql = "select * from Test where test_info = '" & Text1.Text & "'" 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询