CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2000
    Location
    Russia
    Posts
    6

    ADO: How to get the value of RETURN from stored proc

    I want to get the value of RETURN from stored proc but i don't know how.
    Help, please.

    Pail V. Zorin
    zpv73@yahoo.com

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: ADO: How to get the value of RETURN from stored proc

    I'm not sure about Oracle, but I assume it's pretty similar, this is for SQL Server:

    Dim cn as ADODB.Connection
    Dim cmd as ADODB.Command
    Dim lRetVal as Long

    set cn = new ADODB.Connection
    cn.ConnectionString = "Provider=SQLOLEDB;Server=MyServer;User ID=me;Password=mine;"
    cn.Open

    set cmd = new ADODB.Command
    With cmd
    .CommandText = "Name of Stored Procedure Here"
    .CommandType = adCmdStoredProc
    .CommandTimeout = 600 '10 minutes
    .Parameters.Append .CreateParameter("RecordCount", adInteger, adParamReturnValue)
    .Parameters.Append .CreateParameter("@OrderNumber", adInteger, adParamInput)
    .Parameters("@OrderNumber") = iOrderNum
    End With

    cmd.Execute

    'Now check the return status of the proc...
    lRetVal = cmd.Parameters("RecordCount")

    If lRetVal > 0 then
    ...




    NOTE The ReturnValue parameter MUST be the first one declared, all other input/output parameters come after this one. This return value is populated by the stored proc by the "RETURN" command (in SQL Server). This is a typica example of the stored proc above:

    CREATE PROCEDURE sp_MyProcedure (@OrderNum int)
    as

    BEGIN

    DECLARE @RowCount

    SELECT @RowCount = COUNT(*)
    FROM MyOrderTable (nolock)
    WHERE OrderNumber = @OrderNum

    RETURN @RowCount

    END




    Hope this helps,

    John


    John Pirkey
    MCSD
    http://www.ShallowWaterSystems.com
    http://www.stlvbug.org
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Sep 2000
    Location
    Russia
    Posts
    6

    Re: ADO: How to get the value of RETURN from stored proc

    Thanks a lot.


    Pail V. Zorin
    zpv73@yahoo.com

  4. #4
    Join Date
    Jun 2001
    Posts
    2

    Re: ADO: How to get the value of RETURN from stored proc

    Now, how do you do it C++?

    Thanks.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured