_ConnectionPtr pConn;
_RecordsetPtr pRecordset(__uuidof(Recordset));
pRecordset=pConn->Execute("select *from tb_LoginInfo",NULL,adCmdText);
DWORD count;
count=pRecordset->GetRecordCount();
表tb_LoginInfo里有数据为什么pRecordset->GetRecordCount()返回不了表里面有多少条记录呢
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);
pRecordset->GetRecordCount();
试试上面那个吧,不一定要用select count(*),我用的是ODBC的方式连接数据库,用上面两种方式有一种可以得到记录集条数,不知道ado能不能得到,不妨试试~
这个说得对
打开记录集 如果要返回记录数 adOpenDynamic, adLockOptimistic 这个很重要的