如题,部分代码如下
_RecordsetPtr spIDRecord;
spIDRecord.CreateInstance(_uuidof(Recordset)); 
spIDRecord-> CursorType=adOpenStatic;
strSQL.Format(L"SELECT *  FROM LocalUserID");
spIDRecord = m_spAdoCon->Execute((_bstr_t)strSQL,NULL ,adCmdText);
int i = 0;
i = spIDRecord->RecordCount;
i = i+1;
这样写是不是不对,i一直是0还有一个是原来写的 只能得到列数
_RecordsetPtr spIDRecord;
strSQL.Format(L"SELECT *  FROM LocalUserID");
int i;
i= spIDRecord->Fields->GetCount();
i= lCountField+1;

解决方案 »

  1.   

    http://www.wangchao.net.cn/bbsdetail_66853.html
    或者解析SELECT COUNT(*) AS MyCount FROM LocalUserID的记录集
    spIDRecord->Fields->GetCount();得到的是这个记录集的列数,不是行数。
      

  2.   

    1.加上这句IDRecord->CursorLocation = adUseClient;2。或者显示获取表行数
      SELECT count(1) cnt FROM LocalUserID
      

  3.   

    1.加上这句IDRecord->CursorLocation = adUseClient;2。或者显示获取表行数
      SELECT count(1) cnt FROM LocalUserID
      

  4.   

    RecordCount的问题一直很纠结,主要跟游标类型有关系。
    建议采用1楼的方法,得到正确的结果
      

  5.   

    _RecordsetPtr m_pcountRecordset=NULL;   
     m_pcountRecordset.CreateInstance("ADODB.Recordset");
    //获取符合条件的记录总数
    strSQL.Format("SELECT COUNT(*) AS count from xxTable WHERE xxx");
    m_pcountRecordset->Open(_variant_t(strSQL), m_pConnect.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);   var=m_pcountRecordset->GetCollect("count");
    int dCount;
      
    dCount=atoi((LPCTSTR)(_bstr_t)var);