将Ado Recordset动态绑定到Grid控件时出现3704号错误
编号:QA001599
建立日期: 1999年8月26日 最后修改日期:1999年8月26日
所属类别:
JiaQiang Xu:
vb6.0
win95
我将所有新建的Ado Recordset添加到集合,动态绑定到Grid控件,以便保持对Recordset的修改(但暂不保存到数据库中),直到用户作出保存或取消的决定。但当我用集合的成员key引用某个Recordset后,运行Recordset的RecordCount属性,总是出现如下错误:
Run-time error '3704':
The operation requested by the application is not allowed if the object is closed.
代码大致如下:
dim rs as adodb.recordset
dim myrecordset as adodb.recordset
dim coll as collection
set coll=new collection
...
set myrecordset=new recordset
myrecordset.open ".."
....
coll.add myrecordset,key
...
set rs=coll(key)
rs.recordcount
回答:
我已经找到了答案。
用Reocrdset集合大概不行,我改用Recordset的Save方法保存到磁盘文件,
在需要的时候用open方法从该文件重新打开,这样就能在动态绑定过程中保
持对Recordset的修改,最后用UpdateBatch保存到数据库,
with rs
.Save "文件名" '临时保存到磁盘文件
.....
.Open "文件名", "Provider=MSPersist", , , adCmdFile ' 打开文件
.....
'在最终决定保存到数据库之前,重置连接
.ActiveConnection = DataEnvironment1.Connection1.ConnectionString
'保存到数据库
.UpdateBatch adAffectAllChapters
此问题由JiaQiang Xu回答。
| |
|
|
| |
|
|