如何使用CAdoRecordSet获取数据库中字段值????
我现在使用CAdoRecordSet在VC中开发数据库(SQL2000),以下是代码:
if (iStartYear != iEndYear)
strSQL.Format("select * from Table1 where play_year between %d and %d", iStartYear, iEndYear);
else if (iStartMonth != iEndMonth)
strSQL.Format("select * from Table1 where play_month between %d and %d", iStartMonth, iEndMonth);
else
strSQL.Format("select * from Table1 where play_day between %d and %d", iStartDay, iEndDay);
rset.SetAdoConnection(&m_AdoConnection);//记得要先指定相应的连接对象,否则会出错
ret = rset.Open(strSQL, adCmdText, adOpenDynamic, adLockOptimistic);
int nrow = rset.GetRecordCount();
int nTemp = rset.GetFieldsCount();
BYTE bValue = 0;
CString csValue = _T("");
rset.GetCollect(1, csValue);
rset.GetRecordCount()和rset.GetFieldsCount()可以正常获取字段数量和记录数,但是rset.GetCollect(1, csValue)无法获得第一个字段的数值,通过VC的单步调试,发现GetCollect中的 if (m_pRecordset->adoEOF)
{
return FALSE;
}这里退出
不知是哪里还需要注意,请高手指教,谢谢