_bstr_t str1 ("select * from pacs.table1");
pRs1 =  pConnection->Execute(str1,NULL,adOptionUnspecified);
我这句话有问题么?我的pConnection已经打开,str1可以在SQL Plus里面执行,但是为什么在程序里报了IDispatch的错误?

解决方案 »

  1.   

    //先看看错误提示是什么:
    try
    {
    // do your sql function;;
    }
    catch(_com_error * e)

    MessageBox(NULL,"",e->ErrorMessage(),MB_OK);

    catch(...)
    {
    long errorcount=m_pConnection->GetErrors ()->GetCount ();
    char add[255];
    strcpy(add,"");
    for (short i=0;i<errorcount;i++)
    {
    strcat(add,m_pConnection->GetErrors ()->GetItem (_variant_t((short)i))->GetDescription ());
    }
    printf(add);
    }
      

  2.   


    捕捉到的是_com_error的错误
      

  3.   

    HI,把_com_error的错误paste出来哈。
    那几句源程序实在看不出来有什么错,麻烦再多贴点。
      

  4.   

    IDispatch error #3092
    谢谢了
      

  5.   

    try{
    pRs =  m_pAppointConnection->Execute(str,NULL,adOptionUnspecified);
    pRs->Open("select PACS.DFHH from PACS.TABLE1",m_pAppointConnection.GetInterfacePtr(),
    adOpenDynamic,adLockOptimistic,adCmdText);
    }
    catch (_com_error& e) {
    CString errormessage;
    AfxMessageBox("操作错误");
    MessageBox(e.ErrorMessage());
    errormessage.Format("数据库操作!\r\n错误信息:%s",e.ErrorMessage());
    errorfile.WriteError(errormessage);
    PostQuitMessage(0);
    return FALSE;
    }
      

  6.   

    _bstr_t str1 ("select * from pacs.table1");
    加上L
    _bstr_t str1 (L"select * from pacs.table1");
      

  7.   

    pRs =  m_pAppointConnection->Execute(str,NULL,adOptionUnspecified);
    这样就行了,不用再pRs->Open("select PACS.DFHH from PACS.TABLE1",m_pAppointConnection.GetInterfacePtr(),
    adOpenDynamic,adLockOptimistic,adCmdText);否则就需要先加pRs->Close();
      

  8.   

    好好,多谢nustchenhf() 就是因为这个L,我想问一下这个L是做啥用的?
    同时也多谢 ZHENG017() 大力支持
      

  9.   

    L哈,就是让后面的内容变成宽字符,就ascii->unicode.