用MFC ODBC,怎样得到查询记录总数。 直接用GetRecordCount,为什么总得记录为1?
while(!m_pSet->IsEOF( ))
m_pSet->MoveNext( );
调用GetRecordCound可获得记录集中的记录总数,该函数的声明为
long GetRecordCount( ) const;
要注意这个函数返回的实际上是用户在记录集中滚动的最远距离.要想真正返回记录总数,只有调用MoveNext移动到记录集的末尾(MoveLast不行).
方法1:此法应该较好
if (!m_set.IsBOF())
m_set.MoveFirst();
while (!m_set.IsEOF())
m_set.MoveNext();
int i=m_set.GetRecordCount();//i为记录总数
方法2:
CRecordset m_set;
CString strSQL;
strSQL="select count(*) from table1";
m_set.Open(CRecordset::forwardOnly,_T(strSQL),CRecordset::readOnly);
CString str;
m_set.GetFieldValue((short)0,str);
int i=atoi(str);();//i为记录总数