Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim recordcount As Variant
...................
Set rs= conn.Execute("select * from aa")
rs.Save "d:\aa.rec", adPersistXML
recordcount = rs.RecordCount
从输出结果来看可以查询到正确的记录,但是rs.RecordCount这个属性总是为-1,我查看帮助提示是“可能是提供程序或选定的游标类型的限制”,而且rs.Bookmark也出错,也是弹出这个错误信息,不知道是什么原因,怎么解决,请各位高手指教。
2 个解决方案
#1
'加上这句
rs.rs.CursorLocation = adUseClient
Set rs= conn.Execute("select * from aa")
rs.Save "d:\aa.rec", adPersistXML
recordcount = rs.RecordCount
rs.rs.CursorLocation = adUseClient
Set rs= conn.Execute("select * from aa")
rs.Save "d:\aa.rec", adPersistXML
recordcount = rs.RecordCount
#2
rs.CursorLocation = adUseClient
#1
'加上这句
rs.rs.CursorLocation = adUseClient
Set rs= conn.Execute("select * from aa")
rs.Save "d:\aa.rec", adPersistXML
recordcount = rs.RecordCount
rs.rs.CursorLocation = adUseClient
Set rs= conn.Execute("select * from aa")
rs.Save "d:\aa.rec", adPersistXML
recordcount = rs.RecordCount
#2
rs.CursorLocation = adUseClient