CRecordset::GetRecordCount long GetRecordCount( ) const;Return ValueThe number of records in the recordset; 0 if the recordset contains no records; or –1 if the record count cannot be determined.ResCall this member function to determine the size of the recordset. Caution The record count is maintained as a “high water ” — the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count.
......
type mycursor is ref cursor;
......
open mycurosr for 'select .......';
boss叫我做一个报表生成程序,我用ODBC和ORACLE数据库连接,本来都做好了,可是到了公司一看,那儿的ORACLE数据库驱动不支持动态记录集,所以我把我的程序修改如下:
CMySet* m_pDlgSet;(记录集指针)
strSql = CString("select count(*) from els20.event ") +
" where els20.event.eventtype like '火警%' " +
" and els20.event.zeitbeginn between " +
strDate_from[i] + " and LAST_DAY(" + strDate_from[i] + ")";
m_pDlgSet->Open(CRecordset::forwardOnly,strSql,CRecordset::readOnly);
这样就应该是不用动态记录集,而用只支持单向操作的只读记录集了,然后,我要获得count(*)的值,可是当我用下面的语句:
m_pDlgSet->GetFieldValue((int)0,strResult);
却报错:Invalide column number<1>
当我在GetFieldValue上面加上:m_pDlgSet->MoveFirst();语句后,又出现错误:“记录集仅支持向前移动”;这样我想请问,该如何操作,才能取得我要的count(*)的值?
因为boss催的急,还望各位大哥尽快不吝赐教!谢谢!
Invalide column number<1>
是因为列名错误了吧
open()后,
//移到最后一条纪录
while(!m_pDlgSet->IsEof())
{
m_pDlgSet->MoveNext();
}
m_pDlgSet->GetFieldValue((int)0,strResult);
还是报错:非法的游标状态
long GetRecordCount( ) const;Return ValueThe number of records in the recordset; 0 if the recordset contains no records; or –1 if the record count cannot be determined.ResCall this member function to determine the size of the recordset. Caution The record count is maintained as a “high water ” — the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count.
m_pDlgSet->GetFieldValue((int)0,strResult);这条语句就应该没错阿 ,
为何还是出现Invalide column number<1>错误!我昏死!