请问高手:VC怎么样调用Oracle(没有包的)存贮过程??能否给个实例?不胜感谢!!

解决方案 »

  1.   

    使用ODBC直接执行SQL语句也许可以
    CDatabase m_db;
    m_db.OpenEx( _T("DSN=oracle" ),0);
    CString strSql;
       strSql.Format("过程的SQL")
      m_db.ExecuteSQL(strSql); 
        m_db.Close();
      

  2.   

    oh!!my god!!有ADO的吗?不过楼上的"过程的SQL" 就是指过程名吗?输入参数据怎么办?3ku!!
    各位大哥:能不能给个ADO的实例?我对ODBC不是太熟,呵呵!!
      

  3.   

    用谁写一些ADO连ORACLER 的代码出来,我也在做呀,要求是远程的oracle,本地装了客户端,
      

  4.   

    ADO连接Oracle
    AfxOleInit();///初始化COM库
      ////////////连接数据库//////////////
      HRESULT hr;
      try
      {
      hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
      if(SUCCEEDED(hr))
      {
              hr=m_pConnection->Open("Provider=MSDAORA;Persist Security Info=FALSE;Data Source=DSN","UID","PWD",adModeUnknown);
      }
    AfxMessageBox("成功连接");

     
      }
      catch(_com_error e)///捕捉异常
      {
      CString errormessage;
      errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
     
      AfxMessageBox(errormessage);///显示错误信息
      //CDialog::OnCancel();
      //m_fConnected=FALSE;
      return FALSE;

      }
      

  5.   

    msdn中有一个用OLE DB写的例子,名字叫DBView。你看看吧,我也正为存储过程烦呢!
      

  6.   

    ado来解决。
    Create  a dialog based vc application with a 'connect' button and another '
    stored procedure' program.
    On click on connect button to establish connection to the db write the code
    below:
    try
    {
    CoInitialize(NULL);
    HRESULT hr = m_pConn.CreateInstance (__uuidof(Connection));
    if(FAILED(hr)) _com_issue_error(hr); hr = m_pConn->Open(_bstr_t
    ("DSN=xxx;UID=xxx;PWD=xxx"),_bstr_t (""), _bstr_t (""),
    adConnectUnspecified);
    if(FAILED(hr)) _com_issue_error(hr); if (m_pConn->State == adStateOpen)
    {
    AfxMessageBox("Connected to the database");
    } } // end try block
    catch( _com_error &e )
    {
    m_pConn = NULL ;
    _bstr_t bstrDescription (e.Description());
    }2. on click of stored procedure to call the stored procedure with one input
    and one output parameter.
    long nResult=0,nEmpNo = 0;
    _CommandPtr pCommand = NULL;
    _ParameterPtr pName = NULL,pResult = NULL;
    CString strQuery,strService;
    _RecordsetPtr pRecordset;
    //put some  name as present in the db table here
    _bstr_t v_bstrName="ccc"; VARIANT vGetValue;
    vGetValue.vt = VT_BSTR | VT_I4 |VT_R8 | VT_NULL; try
    {
    HRESULT hr = pCommand.CreateInstance (__uuidof (Command));
    if (FAILED(hr)) _com_issue_error(hr); pName = pCommand->CreateParameter("NAME", adBSTR,
    adParamInput,30,v_bstrName);
    pCommand->Parameters->Append(pName);
    pResult= pCommand->CreateParameter("EMP_NO", adInteger,
    adParamOutput,10);
    pCommand->Parameters->Append(pResult); pCommand->ActiveConnection = m_pConn;
    pCommand->CommandText = _bstr_t("EMP");
    pCommand->CommandType = adCmdStoredProc;
    nResult = pCommand->Execute(NULL,NULL,adCmdStoredProc );
    if (nResult == 0)
    {
    AfxMessageBox("Failed to get the employee no.");
    return ;
    } vGetValue = pCommand->Parameters
    ->GetItem("EMP_NO")->GetValue();
    if (vGetValue.vt !=VT_NULL)
    {
    nEmpNo = vGetValue.intVal;
    AfxMessageBox("Success in getting the employee
    no.");
    } else
    AfxMessageBox("Failed to get the employee no.");
    }
    catch ( _com_error &e )
    {
    _bstr_t bstrDescription (e.Description());
    pCommand = NULL;
    pRegNo = NULL;
    pResult = NULL;
    } //uninitialize all the smart pointers to null
    pCommand = NULL;
    pName = NULL;
    pResult = NULL;Hope this helps.
      

  7.   

    CString m_strParam1 = t6+strdh22+t7;
      CString m_strParam2=strdh22;
      _CommandPtr    m_pCommand;
      _ParameterPtr  m_param;
      try
      {
    hr1 = m_pCommand.CreateInstance(__uuidof(Command));
      }
      catch(_com_error *e)
    {
    AfxMessageBox(e->ErrorMessage());
    }
      catch(...)
    {
    AfxMessageBox("ADO建立命令失败!");
    }  m_param = m_pCommand->CreateParameter("FS_FILE",adVarChar, adParamInput,m_strParam1.GetLength()+1,_variant_t(m_strParam1));
      m_pCommand->Parameters->Append(m_param);
      m_param = m_pCommand->CreateParameter("D_N",adVarChar, adParamInput,m_strParam2.GetLength()+1,_variant_t(m_strParam2));
      m_pCommand->Parameters->Append(m_param);  m_pCommand->ActiveConnection = m_pConnection;
      m_pCommand->CommandText = _bstr_t("OPEN_FILES");
      m_pCommand->CommandType=adCmdStoredProc;
      m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
      

  8.   

    你到www.codeguru.com看,现成的,很好用
      

  9.   

    我到www.codeguru.com看了,没找到Oracle的,都是SQL Server的实例,楼上的有没有Oracle的实例?能否给我一份简单的 [email protected]
    感谢!!