|
请教:如何用ADO的RecordSet对象引用当前窗体的记录集?
请教:如何用ADO的RecordSet对象引用当前窗体的记录集?
以前我一直使用DAO的RecordSet对象引用当前窗体的记录集或记录集副本,例如:
Dim Rst As Recordset
Dim lngJLS As Long
Set Rst = ME.RecordsetClone‘记录集副本
或 Set Rst = ME.Recordset
lngJLS = Rst.RecordCount '读取窗体中的记录数
Rst.Close
现在,我想把DAO代码转换成ADO,例如:
Dim lngJLS As Long
Dim Rst As New ADODB.Recordset
Rst.CursorType = adOpenDynamic
Rst.LockType = adLockBatchOptimistic
Set Rst = ME.Recordset
lngJLS = Rst.RecordCount '读取子窗体中的记录数
Set Rst = Nothing
可是运行时,总是系统提示:“运行时错误‘13’类型不匹配”。
我用下列代码查看了当前窗体的记录集属性,
Dim rs As Object
Set rs = ME.Recordset
If TypeOf rs Is ADODB.Recordset Then
MsgBox "ADO Recordset"
Else 'If TypeOf rs Is DAO.Recordset Then
MsgBox "DAO Recordset"
End If
则系统返回提示 “DAO Recordset”。也就是说,当前窗体记录集的默认属性是DAO型。
我将DAO 的引用去掉后再试,结果还是一样。
请问高手、同仁,为什么窗体记录集的默认属性总是DAO型?如何才能使用ADO 的RecordSet对象引用当前窗体的记录集或记录集副本,而使它们类型匹配呢?
我已经试了很多方式,就是解决不了问题,只好向大家请教了。拜托,为盼!
----------------------------------------------
缘系ACCECC,感谢ACCESS中国。 2002-8-18 11:59:14 [code]<SCRIPT language=JavaScript>
var actioninfo3='单帖屏蔽';document.write (dvbbs_show_topic('10976','2','tmtony','','','tmtony@21cn.com','Http://www.office-cn.net|||18449932|||||||||||||||','','Images/userface/image37.gif','','站长',' screen.width-600)this.style.width=screen.width-600;if(this.height>250)this.style.width=(this.width*250)/this.height;">
天大事总平常事 烦恼心皆贪欲心
','','不是的, me.Recordset是一个通用对象,只是因为你使用了jet的绑定,所以缺省就是DAO了,如果你想用它来存ado,使用下面方法
加载时
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT * FROM 你的表"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
Set Me.Recordset = rs
然后你后面引用的me.recordset me.resordsetclone即为ado
','2002-8-18 12:45:37','face0.gif','*.*.*.*','2143',1,0,75,2,'管理员','32','32','2442','2002-1-7','257855','4265','4271','','1',0,'0','level10.gif',1,'2004-8-3 9:47:44',' |
|