_ConnectionPtr pConn;
_RecordsetPtr pRecordset(__uuidof(Recordset));
pRecordset=pConn->Execute("select *from tb_LoginInfo",NULL,adCmdText);
DWORD count;
count=pRecordset->GetRecordCount();
表tb_LoginInfo里有数据为什么pRecordset->GetRecordCount()返回不了表里面有多少条记录呢

解决方案 »

  1.   

    本帖最后由 zyq5945 于 2011-10-27 08:26:14 编辑
      

  2.   

    _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);
      

  3.   

    pRecordset->GetFields()->GetCount();
        pRecordset->GetRecordCount();
    试试上面那个吧,不一定要用select count(*),我用的是ODBC的方式连接数据库,用上面两种方式有一种可以得到记录集条数,不知道ado能不能得到,不妨试试~
      

  4.   


    这个说得对
    打开记录集 如果要返回记录数  adOpenDynamic, adLockOptimistic 这个很重要的
      

  5.   

    原因解释:      GetRecordCount()返回值变成了-1?