void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Data Source=KEZHON-PC\SQLEXPRESS;Initial Catalog=Love;Integrated Security=True";
//连接字符串是在vs2008中建立了一个连接,然后把连接字符串复制过来得到的
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from nets",NULL,adCmdText);
while(!pRst->EOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
编译成功,运行就出问题,大侠帮忙看看,谢谢!
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Data Source=KEZHON-PC\SQLEXPRESS;Initial Catalog=Love;Integrated Security=True";
//连接字符串是在vs2008中建立了一个连接,然后把连接字符串复制过来得到的
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from nets",NULL,adCmdText);
while(!pRst->EOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
编译成功,运行就出问题,大侠帮忙看看,谢谢!
AdoDlg.cpp(180) : warning C4129: 'S' : unrecognized character escape sequence
低级错误
...
}catch(_com_error e){
messagebox(e.description)
}
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
try
{
pConn->ConnectionString="Data Source=KEZHON-PC\\SQLEXPRESS;Initial Catalog=Love;Integrated Security=True"; //"Data Source=KEZHON-PC\\SQLEXPRESS;Initial Catalog=Love;Integrated Security=True"
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from nets",NULL,adCmdText);
}
catch(_com_error e)
{
MessageBox(LPCTSTR(_bstr_t(e.Description));//编译出错的行
} while(!pRst->rsEOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}编译错误:
C:\Users\kezhon\Desktop\PropertyInDlg\Ado\AdoDlg.cpp(193) : error C2440: 'type cast' : cannot convert from '' to 'class _bstr_t'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Users\kezhon\Desktop\PropertyInDlg\Ado\AdoDlg.cpp(193) : error C2143: syntax error : missing ')' before ';'
try...catch捕获的错误是“多步OLE DB操作产生错误。如果可能,请检查每个OLE DB状态值。没有工作被完成。”
这是什么意思。
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Data Source=KEZHON-PC\\SQLEXPRESS;Initial Catalog=Love;Integrated Security=True"; try
{
pConn->Open("","","",adConnectUnspecified);//问题应该出在这一步...... }
catch(_com_error e)
{
MessageBox(e.Description());
}
pRst=pConn->Execute("select * from nets",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox *)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
try
{
pConn->Open("","","",adConnectUnspecified);//问题应该出在这一步...... }
catch(_com_error e)
{
MessageBox(e.Description());
}
我把try...catch的范围缩小到pConn->Open()这一句代码时会弹出“多步OLE DB操作产生错误。如果可能,请检查每个OLE DB状态值。没有工作被完成。” 的错误提示。try...catch其他的语句则不会捕捉到异常提示。
不知道你连的是什么数据库
新建一个udl文件,配置,最后用记事本打开,里面的就是连接字符串