请问如何使用CRecordSet::GetRecordCount ()函数,使得它能正确返回表中记录条数。

解决方案 »

  1.   

    CRecordset 在它的指针未移动到末尾记录时是不会显示正确的记录数的。
      

  2.   

    如果使用Dynaset或Snapshot类型的CRecordset,没有记录,CRecordset::GetRecordCount()返回0;如果有记录,CRecordset::GetRecordCount()返回1。
    要得到真正的记录数,必须在调用CRecordset::GetRecordCount()前调用MoveLast。
    MSDN好像不推荐使用这个方法来获得Recordset的size,其实自己写一个循环最安全
      

  3.   

    陶兄,在调用CRecordset::GetRecordCount()前调用MoveLast,并不能得到真正的记录数,仍然返回1。如果使用循环,对于数十万条记录的表,速度将会很慢,请问还有什么方法迅速得到表的记录数。
      

  4.   

    单纯使用GetRecordCount ()不可能得到记录数的,自己写个循环算一下吧。
      

  5.   

    Caution   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. 这一段是MSDN的描述,如果你觉得不放心,可以用循环;循环觉得开销太大,直接select count(*)算了
    至于有没有别的更好的办法,让我找一下
      

  6.   

    用select count(*)是最好的方法了。
      

  7.   

    对头对头
    刚才看了一下,直接movelast也不行,必须一条条的movenext才行,哈哈,要求老板升级机器吧!
      

  8.   

    一条条的movenext就不用GetRecordCount ()了,先nCount=0,直接在循环的过程中nCount++就行了。