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();
}
编译成功,运行就出问题,大侠帮忙看看,谢谢!

解决方案 »

  1.   

    在连接字符串那一行有一个警告:
    AdoDlg.cpp(180) : warning C4129: 'S' : unrecognized character escape sequence
      

  2.   

    pConn->Open("","","",adConnectUnspecified);
    低级错误
      

  3.   

    双斜杠后编译无错,运行的时候,一点击“查询”,就弹出对话框“Debug Error!”,问中止,重试还是忽略,点击忽略,则弹出对话框曰“Runtime Error!”
      

  4.   

    try{
    ...
    }catch(_com_error e){
    messagebox(e.description)
    }
      

  5.   


    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 ';'
      

  6.   

    真抱歉,犯了个这么愚蠢的错误。
    try...catch捕获的错误是“多步OLE DB操作产生错误。如果可能,请检查每个OLE DB状态值。没有工作被完成。”
    这是什么意思。
      

  7.   

    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"; 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();
    }
      

  8.   


    try 

    pConn->Open("","","",adConnectUnspecified);//问题应该出在这一步...... } 
    catch(_com_error e) 

            MessageBox(e.Description()); 

    我把try...catch的范围缩小到pConn->Open()这一句代码时会弹出“多步OLE DB操作产生错误。如果可能,请检查每个OLE DB状态值。没有工作被完成。” 的错误提示。try...catch其他的语句则不会捕捉到异常提示。
      

  9.   

    你的连接字符串...
    不知道你连的是什么数据库
    新建一个udl文件,配置,最后用记事本打开,里面的就是连接字符串