VB一直提示recordset 对象关闭时不允许操作
我想做个登陆界面,是这样写的PrivateSubCommand1_Click()DimcnnAsNewADODB.ConnectionDimrs1AsNewADODB.R...
我想做个登陆界面,是这样写的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 ("use 车辆管理正式版 select * from zhanghu where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'") If rs1.EOF = True Then MsgBox "用户名或密码错误!", vbInformation, "警告"Text1.Text = "" Text2.Text = "" Else Unload Me MsgBox "登录成功"Form2.Show End If rs1.Close End Sub每次到If rs1.EOF = True Then那里就会出错。。。提示recordset 对象关闭时不允许操作怎~么回事,请大家帮我看下,谢谢了
展开
3个回答
展开全部
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
展开全部
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就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是不是在哪里把Recordset给Close,刚我也是。我是Recordset与Excel关联着,没关闭,所以导致VB打开Excel时一直打不开
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询