您的位置:首页 > 编程语言 > PHP开发

关于_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 ;

之后GetRecordCount()的返回值就是对的了。

或者向下遍历一遍也可,因为:“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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: