|
请看原代码:
BOOL CMyApp::InitInstance()
{
...
AfxOleInit();
pConn.CreateInstance(__uuidof(Connection));
try
{
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ki.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库POP.mdb是否在当前路径下!");
return false;
}
return FALSE;
}
extern CMyApp theApp;
void Show()
{
CString str;
str="select * from Name";
_RecordsetPtr m_pRs;
try
{
m_pRs=theApp.pConn->Execute((_bstr_t)str,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
catch(...)
{
AfxMessageBox("打开数据集错误1!");
}
}
运行后:显示“无效指针”的错误 |
|