数据库的记录个数
我使用以下语句打开数据库,
如何获取当前CRecordset中记录的记录个数!!!!F_SQL="Select * from Information Where number='0000000003'";
m_DS.Open(AFX_DB_USE_DEFAULT_TYPE,F_SQL);
我使用以下语句打开数据库,
如何获取当前CRecordset中记录的记录个数!!!!F_SQL="Select * from Information Where number='0000000003'";
m_DS.Open(AFX_DB_USE_DEFAULT_TYPE,F_SQL);
设置一个整型变量
用一个循环,遍历一遍
CRecordset
例如
int number=0;
while(!m_Ds.IsEOF())
{
number++;
}
这样就可以了,number就是记录的个数了
应该可以吧。
Call this member function to obtain the current setting for the number of rows you wish to retrieve during a given fetch.
Call this member function to obtain the current setting for the number of rows you wish to retrieve during a given fetch.恕我无知,,这是什么意思???CRecordset中没有这个函数!!!
m_DS.MoveFirst();while(!m_Ds.IsEOF())
{
m_Ds.MoveNext;
}int nCount = m_Ds.GetCount();对于大数据量的,这种方法不好
就OK吧
F_SQL="Select count(*) from Information Where number='0000000003'";
m_DS.Open(AFX_DB_USE_DEFAULT_TYPE,F_SQL);
m_DS.GetFieldValue(int(0),MyCount);
//MyCount 就是你想要得
m_pRecordset->Open(CRecordset::dynaset,strSQL)
while(!m_pRecordset->IsEOF())
{
m_pRecordset->MoveNext();
}
m_pRecordset->GetRecordCount();
HRESULT hr = NOERROR;
IADORecordBinding *piAdoRecordBinding = NULL;
_RecordsetPtr rs;
rs.CreateInstance(__uuidof(Recordset));
rs->CursorLocation = adUseClient;
CmaintainlistRs pRs;
rs->Open("select * from tablename" ,(IDispatch *)M_pConnection,adOpenDynamic,
adLockBatchOptimistic, adCmdUnspecified);
if (FAILED(hr = rs->QueryInterface(__uuidof(IADORecordBinding), (LPVOID *)&piAdoRecordBinding)))
_com_issue_error(hr);
if (FAILED(hr = piAdoRecordBinding->BindToRecordset(&pRs)))
_com_issue_error(hr);rs->RecordCount;
要先遍历,GetRecordCount()才行
或者
m_pRecordset->equery();
m_pRecordset->GetRecordCount();