Accessing ADO output parameters from SQL Server to VC++.net

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: nadimpal99 (nadimpal99_at_discussions.microsoft.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 07:19:08 -0700

I have a stored procedure in SQL Server database with one input and one
output parameters. I am able to run the stored procedure from VC++ through
ADO, but cannot access the output value. I am new to ADO through VC++.
Please find my VC++ code below. Any help/suggestions appreciated.

/****************************************************/
        _CommandPtr myCmd;
        _ParameterPtr myPrm;
        int myTag;
        VARIANT vtTag;
        VARIANT vtRtn;
        _variant_t field;
        _bstr_t sSize;
        int rtn;
        HRESULT hr;

                rtn = ds_sql_connect_host();

                hr = myCmd.CreateInstance(__uuidof(Command));
                if(FAILED(hr))
                {
                        printf("Can't Create an instance of Command!\n");
                        return 0;
                }

                myCmd->CommandText = "mhc_new_spool";
                myCmd->CommandType = adCmdStoredProc;
                myTag = 1076806;
                vtTag.vt = VT_INT;
                vtTag.intVal = myTag;
                myPrm = myCmd->CreateParameter("tag", adInteger, adParamInput,
sizeof(int), vtTag);
                myCmd->Parameters->Append(myPrm);
                myPrm->Value = vtTag;

                vtRtn.vt = VT_INT;
                myPrm = myCmd->CreateParameter("rtn", adInteger, adParamOutput,
sizeof(int), vtRtn);
                myCmd->Parameters->Append(myPrm);
                myPrm->Value = vtRtn;

                myCmd->ActiveConnection = DBconnP;
                
                myCmd->Execute(NULL, NULL, adCmdStoredProc);
                rtn = (int)(vtRtn.intVal);
/****************************************************/

-- 
nadimpal99


Relevant Pages

  • Accessing ADO output parameters from SQL Server to VC++
    ... I have a stored procedure in SQL Server database with one input and one ... output parameters. ... ADO, but cannot access the output value. ...
    (microsoft.public.data.ado)
  • Stored Procedures
    ... I will be using MS Access to insert rows into a SQL server database. ... know how to do this using recordsets / ADO. ... insert the rows one at a time using a stored procedure. ...
    (microsoft.public.sqlserver.programming)
  • Re: DBD::Sybase and $sth->{syb_result_type} v. DBD::ODBC (Sql Server)
    ... write output parameters and return a value. ... individual operations in the procedure by calling odbc_more_results. ... Things get a little more complex for what I guess Sybase calls CS_MSG_RESULT ... the status from a stored procedure was ...
    (perl.dbi.users)
  • Re: SQL Server stored prcedures with output parameters
    ... the stored procedure below appears to consistently ... > moment) how ADO handles that. ... Parameter 1 had direction input ... Appending parameter value http://www.holdenweb.com/ ...
    (comp.lang.python)
  • Re: Stored Procedure is running slow!
    ... > I run stored procedure from QA, it takes some 15 seconds to execute. ... > seconds when called from MS Fox Pro, via ADO. ... Try this in Query Analyzer: ... By default Query Analyzer runs with ARITHABORT ON, ...
    (microsoft.public.sqlserver.programming)