Getting Output Parameter from _CommandPtr
-
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
-
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
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
-
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