关于_RecordsetPtr下GetRecordCount函数的使用注意
2016-12-28 14:44
190 查看
_RecordsetPtr对象的GetRecordCount()方法总是返回-1
_RecordsetPtr对象的GetRecordCount()方法总是返回-1,而实际上是有数据的。在csdn上看到了一个帖子,解决办法是(经测试可行):注意记录集的类型和游标类型,将游标类型设置为adUseClient(客户端游标)。
_RecordsetPtr pRs = NULL;
pRs->CursorLocation = adUseClient;
1 2 | _RecordsetPtr pRs = NULL ; pRs -> CursorLocation = adUseClient ; |
或者向下遍历一遍也可,因为:“The record count is maintained as a “high water mark” — the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record.”。
也就是说,GetRecordCount()返回的是数据表曾经移动到的最大记录号,因此只有通过MoveNext()方式直到adoEOF为TRUE之后,GetRecordCount()才会返回正确的记录数。
如果不是特别需要,还是用EOF比较好,因为GetRecordCount()在其他人操作数据库时(比如增加操作),得到的数也有可能是错误的。
经过测试,将游标类型设置为adUseClient之后,GetRecordCount()的返回值确实就正确了。但最后我还是只采用了MoveNext()+adoEOF的方式,弃用了GetRecordCount()。
以上知识属于转载内容,详情请点击原帖地址: http://bbs.csdn.net/topics/60396154
相关文章推荐
- 关于使用存储过程的一些好处以及注意事项
- 在Asp.net 2.0中关于menu和treeview的几点使用注意!
- 关于Flex使用Blazeds连接Java后台的一个注意笔记
- 关于使用存储过程的一些好处以及注意事项
- 关于mojoportal在局域网或单机使用时注意事项
- 注意关于花露水的4大使用误区 - 生活至上,美容至尚!
- 关于使用存储过程的一些好处以及注意事项
- 关于使用索引(Index)的一些注意点
- vc++中_RecordsetPtr使用
- 关于使用标签需要注意的几个问题
- boost shared_ptr 使用注意点。
- 关于在Linux下使用select函数需要注意的地方
- 在WEB程序中使用.NET Remoting的IpcChannel时注意事项(关于“拒绝访问”问题的解决)
- 关于SelectOjbect使用需要注意的一些问题
- 智能指针auto_ptr使用注意事项
- 关于Java开发中使用Oracle数据库的一点注意事项
- 智能指针auto_ptr使用注意事项
- 关于数据库中使用 left join on ...and ...和 left join on ....where ...区别,和使用group by 要注意的情况
- 关于使用READ TABLE语句的几点注意事项
- 关于使用存储过程的一些好处以及注意事项[转]