GetRecordCount ============== The record count is maintained as a “high water ” — 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. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count.
{
m_recordset->MoveNext();
...................
......................
}
m_recordset->GetRecordCount();
一定是要MoveNext()的!
十分关注,我在用ODBC编程时也遇到了一模一样的问题,GetRecordCount()总是返回1。jjqiao710102(aqiao) 的方法也许可以,
当时我的办法只有先MoveFirst( ),再判断IsEOF(),然后再MoveNext(),一个一个加下去,最后才得到结果,但这样做也太蠢了
==============
The record count is maintained as a “high water ” — 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. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count.
zhuojohn(闲云野鹤) 所说的是在MSDN上GetRecordCount()的Re,我早就看过几遍,想来想去还真的只有用如下方法才行:定义一个成员变量m_nCount,用于记录当前recordset的record个数;
自定义一个Count()函数,功能就是像上面说的"蠢方法"
MoveFirst( ),再判断IsEOF(),然后再MoveNext(),一个一个加下去,
然后在每次open()之后都调用Count( )
最后在添加 或 删除 操作后,记得加上加一或减一 m_nCount ... ...至于GetRecordCount(),让它食屎拉
select count(1) from table where 条件
如果有记录,再执行真正的查询
这样效率应该好些,我一直是这样处理的:)GetRecordCount()是在你处理完记录之后用的
使用静态游标就可以了。
缺省是动态游标,数据并不全部下载到本地,以加快速度。
另外的解决方案,就是使用查询语句select count(*)
改变游标是不是就是指改变CRecordset::的枚举植啊,不过这样做就没有动态集的好处了吧
SELECT COUNT还是可以考虑的,谢谢