关于GetRecordCount()函数的问题。

sad_4978 2003-09-11 11:37:35
我用的接口是ODBC,想通过GetRecordCount()函数返回记录结果集中的存储记录的条数。
可是不管数据库中的记录有多少条返回值总是1。但程序正常运行,这是怎么回事?
...全文
276 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjz800800 2003-09-12
  • 打赏
  • 举报
回复
便利所有记录,然后就可得到记录数值
storein 2003-09-11
  • 打赏
  • 举报
回复
好像是你使用的游标不对,具体我也不清楚,你看看以前的帖子
有关于这个问题的介绍
你在执行查询前加上这条语句
m_pConnection->CursorLocation = adUseClient; 将返回正确的记录数
whoishere 2003-09-11
  • 打赏
  • 举报
回复
MSDN中有解释:
The record count is maintained as a “high water mark” — 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.
也就是说,GetRecordCount返回的是数据表曾经移动到的最大记录号,因此只有你通过MoveNext方式直到IsEOF返回TRUE之后,GetRecordCount才会返回正确的记录数。
yoyo2002 2003-09-11
  • 打赏
  • 举报
回复
DWORD GetRecordCount(_RecordsetPtr m_pRecordSet)
{
DWORD dwRows = 0;

dwRows = m_pRecordSet->GetRecordCount();

if(dwRows == -1)
{
if(m_pRecordSet->EndOfFile != VARIANT_TRUE)
pRecordSet->MoveFirst();

while(pRecordSet->EndOfFile != VARIANT_TRUE)
{
dwRows++;
pRecordSet->MoveNext();
}
if(dwRows > 0)
pRecordSet->MoveFirst();
}
return dwRows;
}
wuchuncai 2003-09-11
  • 打赏
  • 举报
回复
GetRecordCount打开时用以下的选项,应该可以。
m_pUserSet->Open((_variant_t)sql,
m_pConnection.GetInterfacePtr(),
adOpenStatic,
adLockOptimistic,
adCmdText);
nalo 2003-09-11
  • 打赏
  • 举报
回复
必须将所有的纪录遍历一遍,才能取得正确的count
cdwy411 2003-09-11
  • 打赏
  • 举报
回复
the recordset move from head to tail
you must use MoveNext() or the rusult may be wrong!
cdwy411 2003-09-11
  • 打赏
  • 举报
回复
其实你可以用一个变量记录它,
从记录集的开始一直移到结尾!
注意移动的时候一定要用MoveNext()
其他的不行!
MHB 2003-09-11
  • 打赏
  • 举报
回复
同意楼友 whoishere(我来也) 的
llm06 2003-09-11
  • 打赏
  • 举报
回复
肯定和你打开记录集的方式有关,使用dynamic方式可能会有问题,用static方式试一下

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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