//代码段
_RecordsetPtr CADO::GetResultSet(CString sql)
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset)); _CommandPtr pCommand;
pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection = m_pConnection;
//m_pConnection已经连上,利用m_pConnection执行sql语句也能成功 pCommand->CommandText = _bstr_t(sql);
pCommand->CommandType = adCmdText;
pCommand->Parameters->Refresh();
try{
m_pRecordset = pCommand->Execute(NULL,NULL,adCmdText);//这里报错,no database selected
return m_pRecordset;
}catch(_com_error e)
{
CString cs;
cs.Format("%s%s","getresultset fail;",(LPCSTR)e.Description());
AfxMessageBox(cs);
return NULL;
}
}搞大半天了,真疯了,网上也没找到相关的东西,_CommandPtr用法照网上来的,都是这样用的!!! 不懂到底哪出毛病了
_RecordsetPtr CADO::GetResultSet(CString sql)
{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset)); _CommandPtr pCommand;
pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection = m_pConnection;
//m_pConnection已经连上,利用m_pConnection执行sql语句也能成功 pCommand->CommandText = _bstr_t(sql);
pCommand->CommandType = adCmdText;
pCommand->Parameters->Refresh();
try{
m_pRecordset = pCommand->Execute(NULL,NULL,adCmdText);//这里报错,no database selected
return m_pRecordset;
}catch(_com_error e)
{
CString cs;
cs.Format("%s%s","getresultset fail;",(LPCSTR)e.Description());
AfxMessageBox(cs);
return NULL;
}
}搞大半天了,真疯了,网上也没找到相关的东西,_CommandPtr用法照网上来的,都是这样用的!!! 不懂到底哪出毛病了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货