rs->GetRecordCount()
-->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. (MSDN)

解决方案 »

  1.   

    但是用rs->Open("select * from mytable", ...)
    返回的记录集GetRecordCount()的返回值是对的
      

  2.   

    _CommandPtr::Execute返回记录集的光标类型为:adOpenForwardOnly,
    在这种情况下你得不到记录总数
      

  3.   

    是啊,可是如何让_CommandPtr返回记录集的光标类型改变呢。
      

  4.   

    用Select count(*) from Table
      

  5.   

    谢谢以上各位:
       我想在执行存储过程后返回光标(Cursor)可以自由移动的记录集,
    可是现在返回的记录集只能调用MoveFirst和MoveNext,调用MoveLast即出现
    异常(因为记录集的Cursor类型为adOpenForwardOnly)。请问应该怎么办?
      

  6.   

    该问题我碰过
    设定客户端游标
    _RecordsetPtr pRs->CursorLocation=adUseClient;open时候采用参数adOpenKeyset
    pRs->Open( SQL,
    _variant_t((IDispatch *)pConn,true),
    adOpenKeyset,
    adLockReadOnly,
    -1 ); 这时候 返回的记录集GetRecordCount()的返回值就是对的
      

  7.   

    wnchg说的对,应该设计打开游标的类型,你用的打开方式是
    dynamic,此时recordCount就是为-1,设置为readonly就可以
    使用得到正确的结果
      

  8.   

    vc不适合对数据库进行操作,微软的ADO应用到VC当中的时候在读取结果集的时候一般都得到的是错误的结果,大量的程序已经证明了这一点。所以用GetRecordCount()函数一般都不准,可以用循环取得结果集的个数。