extern CADOApp theApp;//这里对全局对象的引用是否正确
void CADODlg::OnBtnInfo()
{
try
{
m_pRec->Open("select * from Info",\
theApp.m_pConn.GetInterfacePtr(),\
adOpenDynamic,\
adLockOptimistic,\
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("建立数据记录集失败");
}
}
为什么运行错误,跟踪在open函数出错
请教高手!
void CADODlg::OnBtnInfo()
{
try
{
m_pRec->Open("select * from Info",\
theApp.m_pConn.GetInterfacePtr(),\
adOpenDynamic,\
adLockOptimistic,\
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("建立数据记录集失败");
}
}
为什么运行错误,跟踪在open函数出错
请教高手!
_variant_t((IDispatch*)theApp.m_pConn
theApp.m_pConn有正确连接数据库吗?
不行就看看是什么错误呢
把
catch(_com_error e)
{
AfxMessageBox("建立数据记录集失败");
}
改成
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
在打开之前先做个连接判断:
if(m_pConnection==NULL)//连接为空
OnInitADOConn();//建立连接,这个接口你应该会写吧;