为什么编译时提示:'_ConnectionPtr' : undeclared identifier

ildp 2006-08-21 08:49:12
在对话框的OnInitDialog中放置如下代码:
——————————————————————————————————
CDialog::OnInitDialog();

CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command));

pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\config.mdb;Persist Security Info=false;";
pConn->Open("","","",adConnectUnspecified);

pCmd->put_ActiveConnection(_variant_t((IDispatch*)pConn));
pCmd->CommandText="select * from conn";
pRst=pCmd->Execute(NULL,NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_HOST_LIST))->AddString(
(_bstr_t)pRst->GetCollect("HostName"));
pRst->MoveNext();
}

pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();

return TRUE;
——————————————————————————————————
编译时竟然提示_ConnectionPtr、_RecordsetPtr、_CommandPtr是undeclared identifier。不知道是什么原因?(我在stdafx.h中已经添加了#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF"))


...全文
970 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
handsomerun 2006-08-21
  • 打赏
  • 举报
回复
var = pRecordset->GetCollect(_T("field"));
if(var.vt!=VT_NULL)
{
CString str= (LPCTSTR)_bstr_t(var);
}


handsomerun 2006-08-21
  • 打赏
  • 举报
回复
http://blog.csdn.net/handsomerun/archive/2006/08/12/1055311.aspx
ildp 2006-08-21
  • 打赏
  • 举报
回复
还想请教一下:
怎么将pRst->GetCollect("HostName")的值赋给一个CString变量呢?
怎样将pRst->GetCollect("id")的值赋给一个int变量呢?
handsomerun 2006-08-21
  • 打赏
  • 举报
回复

对话框的cpp文件,包含了StdAfx.h的吧
ildp 2006-08-21
  • 打赏
  • 举报
回复
我将#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")语句放到对话框的CPP文件中,编译就正常了。
真是奇怪,我在对话框的CPP文件中包含了StdAfx.h呀。
handsomerun 2006-08-21
  • 打赏
  • 举报
回复
在StdAfx.h中,加入如下代码
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")

然后定义
_ConnectionPtr m_pAppConn;

就可以了阿,很奇怪,为什么会出现这样的错误阿

你新建一个新的工程,试试呢???

4,011

社区成员

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

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