VC连接数据库是获取记录集出现问题

yelingshen 2009-05-02 04:11:37
BOOL CAdoRWAccessDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
// 使用ADO创建数据库记录集
m_pRecordset.CreateInstance(__uuidof(Recordset));

// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。jingzhou xu

try
{

m_pRecordset->Open("SELECT * FROM DemoTable", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
运行时出现了、
H:\AdoRWAccess\AdoRWAccessDlg.cpp(60) : error C2065: 'theApp' : undeclared identifier
H:\AdoRWAccess\AdoRWAccessDlg.cpp(60) : error C2228: left of '.m_pConnection' must have class/struct/union type
H:\AdoRWAccess\AdoRWAccessDlg.cpp(60) : error C2228: left of '.GetInterfacePtr' must have class/struct/union type
执行 cl.exe 时出错.
...全文
46 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4,017

社区成员

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

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