如何使用CAdoRecordSet获取数据库中字段值????

yangyi198381 2013-06-22 06:25:00
我现在使用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;
}这里退出
不知是哪里还需要注意,请高手指教,谢谢
...全文
97 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧