您的位置:首页 > 数据库

MFC用 ADO连接数据库,get_RecordCount总是返回-1解决办法

2012-10-05 12:09 447 查看
1.将数据库连接属性设置一下就行了,如你的连接指针变量是m_pConnection,可以这样:

::CoInitialize(NULL);

m_pConnection.CreateInstance(_uuidof(Connection)); //初始化Connection指针



m_pConnection->CursorLocation = adUseClient;



。。。。

。。。。

2.遍历数据

long n = 0;

while(!myRecordset-> adoEOF)

{

n++;

myRecordset-> MoveNext();

}

3.通过Sql语句

Select Count(*)

from 表

where 条件

m_pPtr = m_paConnection->Execute((_bstr_t)strSQL, NULL, adCmdText);

_variant_t vIndex = (long)0;

_variant_t vCount =m_pPtr->GetCollect(vIndex);

long nNum = vCount.ulVal;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: