VC连接数据库是获取记录集出现问题
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 时出错.