VB一直提示recordset 对象关闭时不允许操作
发布网友
发布时间:2023-04-22 08:32
我来回答
共3个回答
热心网友
时间:2023-10-18 17:05
Private Sub Command1_Click()
Dim cnn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim cmd As New ADODB.Command
cnn.ConnectionString = "provider=SQLOLEDB.1;Persist Security Info=False;Integrated Security=SSPI;CATALOG=车辆管理正式版;"
cnn.Open
Set rs1.ActiveConnection = cnn
rs1.Open "select * from zhanghu where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'"
If rs1.EOF Then
MsgBox "用户名或密码错误!", vbInformation, "警告"
Text1.Text = ""
Text2.Text = ""
Else
MsgBox "登录成功"
Form2.Show
Unload Me
End If
rs1.Close
End Sub
热心网友
时间:2023-10-18 17:06
Private Sub Command1_Click()
Dim cnn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim cmd As New ADODB.Command
cnn.ConnectionString = ("provider=SQLOLEDB.1;Persist Security Info=False;Integrated Security=SSPI;CATALOG=车辆管理正式版;")
cnn.Open '11111111111111111111111
Set rs1.ActiveConnection = cnn
rs1.Open ("use 车辆管理正式版 select * from zhanghu where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'") '222222222222222
If rs1.EOF = True Then
MsgBox "用户名或密码错误!", vbInformation, "警告"Text1.Text = "" Text2.Text = ""
Else
Unload Me MsgBox "登录成功"
Form2.Show
End If
rs1.Close '333333333333333333333
End Sub
看你出现错误的地方了,1的地方检察连接字符串,2的地方有明显错误“use 车辆管理正式版”这个局去掉,3的地方:直接去掉rs1.close就可以了
热心网友
时间:2023-10-18 17:06
你是不是在哪里把Recordset给Close,刚我也是。我是Recordset与Excel关联着,没关闭,所以导致VB打开Excel时一直打不开