Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting Output Parameter from _CommandPtr

Getting Output Parameter from _CommandPtr

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex1205
    wrote on last edited by
    #1

    I am currently trying to get the return value and output parameters of a stored procedure using ADOs _CommandPtr. As I have researched it should be as simple as the code below: ///////////////////////////////////////////////////////////////////// _CommandPtr m_pCommand; _RecordsetPtr rsRecord; _ParameterPtr pParam; _variant_t vNull, vValue, vNew; vNull.vt = VT_ERROR; vNull.scode = DISP_E_PARAMNOTFOUND; m_pCommand->ActiveConnection = m_pConnection; m_pCommand->CommandType = adCmdStoredProc; m_pCommand->CommandText = _bstr_t("au_info_all"); pParam = m_pCommand->CreateParameter(_bstr_t("@ReturnCode"), adInteger, adParamReturnValue, sizeof(int), vNew); m_pCommand->Parameters->Append(pParam); m_pCommand->Parameters->Append( m_pCommand->CreateParameter ( _bstr_t("@au_lname"), adVarChar, adParamInput, 40, _variant_t("Green") ) ); rsRecord = m_pCommand->Execute(&vNull, &vNull, adCmdStoredProc ); intTest = pParam->GetValue().lVal; strTest.Format(_T("%d"), intTest); ::MessageBox(NULL, _bstr_t(strTest), _T(""), MB_OK); /////////////////////////////////////////////////////////////// But the value that I got is always 0. This is not the same case when I use Query Analyzer. Is there anything else that needs to be done? Thank you. SDE

    R 1 Reply Last reply
    0
    • A alex1205

      I am currently trying to get the return value and output parameters of a stored procedure using ADOs _CommandPtr. As I have researched it should be as simple as the code below: ///////////////////////////////////////////////////////////////////// _CommandPtr m_pCommand; _RecordsetPtr rsRecord; _ParameterPtr pParam; _variant_t vNull, vValue, vNew; vNull.vt = VT_ERROR; vNull.scode = DISP_E_PARAMNOTFOUND; m_pCommand->ActiveConnection = m_pConnection; m_pCommand->CommandType = adCmdStoredProc; m_pCommand->CommandText = _bstr_t("au_info_all"); pParam = m_pCommand->CreateParameter(_bstr_t("@ReturnCode"), adInteger, adParamReturnValue, sizeof(int), vNew); m_pCommand->Parameters->Append(pParam); m_pCommand->Parameters->Append( m_pCommand->CreateParameter ( _bstr_t("@au_lname"), adVarChar, adParamInput, 40, _variant_t("Green") ) ); rsRecord = m_pCommand->Execute(&vNull, &vNull, adCmdStoredProc ); intTest = pParam->GetValue().lVal; strTest.Format(_T("%d"), intTest); ::MessageBox(NULL, _bstr_t(strTest), _T(""), MB_OK); /////////////////////////////////////////////////////////////// But the value that I got is always 0. This is not the same case when I use Query Analyzer. Is there anything else that needs to be done? Thank you. SDE

      R Offline
      R Offline
      RChin
      wrote on last edited by
      #2

      Having compared your code with the one that I use, it looks perfectly fine, except that I instantiated an instance of my command pointer before use:

      TESTHR( pCmd.CreateInstance(__uuidof(Command)) );
      pCmd->CommandText = _T("sproc_thingy");
      pCmd->CommandType = adCmdStoredProc;
      ..
      ..
      //etc.
      

      This my be your problem.


      I Dream of Absolute Zero

      A 1 Reply Last reply
      0
      • R RChin

        Having compared your code with the one that I use, it looks perfectly fine, except that I instantiated an instance of my command pointer before use:

        TESTHR( pCmd.CreateInstance(__uuidof(Command)) );
        pCmd->CommandText = _T("sproc_thingy");
        pCmd->CommandType = adCmdStoredProc;
        ..
        ..
        //etc.
        

        This my be your problem.


        I Dream of Absolute Zero

        A Offline
        A Offline
        alex1205
        wrote on last edited by
        #3

        Thanks. I have seen a solution to it. In order for output parameters to be retrieved properly, the ActiveConnection's Cursor type should be set to adUseClient before calling the execute method. Thank you for the reply. :> SDE

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups