菜鸟之菜鸟问题啊,为什么vb老是提示我“对象打开时,操作不被允许”

webnumen 2003-04-01 11:31:06
Dim SqlStr As String
SqlStr = "Select * From bumen where xm='" & Text2.Text & "'"
Conn.Execute SqlStr
Query.Recordset.Open SqlStr, Conn, 1, 1// 到这一句时,总提示“对象打开时,操作不被允许”
...全文
17 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xinshou1979330 2003-04-01
同意楼上的做法
dim conn as adodb.connection
dim rs as adodb.recordset
dim provider as string
dim dbpath as string
dim sqlstr as string
provider="provider=提供者;"
dbpath="data source=数据库路径及名"
set conn=new adodb.connection
conn.open provider & dbpath
SqlStr = "Select * From bumen where xm='" & Text2.Text & "'"
set rs=new adodb.recordset
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic


回复
juzi110 2003-04-01
你是否在工程里引用了ado的对象了
引用之后你在加上
dim conn as adodb.connection
dim rs as adodb.recordset
dim provider as string
dim dbpath as string
dim sqlstr as string
provider="provider=提供者;"
dbpath="data source=数据库路径及名"
set conn=new adodb.connection
conn.open provider & dbpath
set rs=new adodb.recordset
SqlStr = "Select * From bumen where xm='" & Text2.Text & "'"
rs.open sqlstr,conn,cursor,2
这样子就可以打开数据库及你所要招行的sql操作
回复
qqqdong 2003-04-01
Query是啥东西需要定义呀

例如:
dim Query AS ADODB.RecordSet
Set Query = New ADODB.RecordSet
Query.Open SqlStr, Conn, 1, 1

回复
sxs69 2003-04-01
Dim SqlStr As String
SqlStr = "Select * From bumen where xm='" & Text2.Text & "'"
Query.Recordset.close
Query.Recordset.Open SqlStr, Conn, 1, 1//
回复
webnumen 2003-04-01
to sxs69
还是不行啊,这一段Conn.Execute SqlStr去掉也不行
回复
wingsk_cn 2003-04-01
楼主重复打开BUMEN两次了,所以第二次打开的时候就提示对象打开时,操作不被允许
回复
sxs69 2003-04-01
Dim SqlStr As String
SqlStr = "Select * From bumen where xm='" & Text2.Text & "'"

Query.Recordset.Open SqlStr, Conn, 1, 1//
回复
heipifeng 2003-04-01
Conn.Execute SqlStr
Query.Recordset.Open SqlStr, Conn, 1, 1// 到这一句时,总提示“对象打开时,操作不被允许”
你执行了两次啊。
回复
饮水需思源 2003-04-01
Query.Recordset.Open SqlStr, Conn, 1, 1
这句前面加一句:if query.state=adstateopen then query.close
query.open sqlstr,conn,1,1


回复
饮水需思源 2003-04-01
Query.Recordset.Open SqlStr, Conn, 1, 1
回复
lxcc 2003-04-01
'Conn.Execute SqlStr 这一句就不要了
Query.Recordset.Open SqlStr, Conn, 1, 1// 到这一句时,总提示“对象打开时,操作不被允许”
回复
gsutnese 2003-04-01
应该操作完后关闭
close rs
set rs =nothing
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-04-01 11:31
社区公告
暂无公告