VB连接SQL出现“实时错误3704,对象关闭时,不允许操作”的错误?
DimconnAsNewADODB.ConnectionDimrstAsNewADODB.RecordsetDimsqlsearchAsStringDimsqlinser...
Dim conn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim sqlsearch As String Dim sqlinsert As StringPrivate Sub Command1_Click() '登录单击按钮事件 Set conn = New ADODB.ConnectionIf Text1.Text = "" Then MsgBox "大王你没有填写登录用户名,请填写!", 16, "提示!" Exit SubEnd IfIf Text2.Text = "" Then MsgBox "大王你没有填写登录用户密码,请填写!", 16, "提示!" Text2.SetFocus Exit SubEnd Ifconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\a.accdb;Persist Security Info=False"conn.Open sqlsearch = "Select * From 用户注册表 Where 用户名='" & Text1.Text & "'"rst.Open sqlsearch, conn, adOpenKeyset, adLockOptimisticIf rst.EOF ThenMsgBox "你是假大王(没有这个用户,请重新输入用户名)!"conn.CloseText1.Text = " "Text2.Text = ""Text1.SetFocusElseIf Trim(rst.Fields("密码")) = Trim(Text2.Text) ThenForm2.ShowUnload MeElseMsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"CloseText2.Text = ""Text2.SetFocusEnd Ifrst.Close End Sub
展开
展开全部
问题到底错在哪行呢?
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\a.accdb;Persist Security Info=False"
conn.Open
是这里吗?
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\a.accdb;Persist Security Info=False"
conn.Open
是这里吗?
更多追问追答
追答
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
Close
这个close,是close什么对象的?
建议
If rst.EOF Then
MsgBox "你是假大王(没有这个用户,请重新输入用户名)!"
conn.Close
Text1.Text = " "
Text2.Text = ""
Text1.SetFocus
ElseIf Trim(rst.Fields("密码")) = Trim(Text2.Text) Then
Form2.Show
Unload Me
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
Close
Text2.Text = ""
Text2.SetFocus
End If
这里要么每条if分支都加上rst.close要么都不加,只要最后一句用rst.close,否则很容易出错
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询