locked
Getting return values from stored procedures RRS feed

  • Question

  • User-1830216367 posted

    I have a stored procedure with input parameters and one output parameter with the Primary Key being returned in the single output parameter.

    After my insert code is run, I issue a RETURN command.  I would like to be able to do something like RETURN -1 or RETURN 12345 to give my asp.net a status code in addition to the output parameter containing the PK.

    However, I can't figure out how to actually get the data from the RETURN statment.  I saw some code which referenced getting that return value like this:


    dim return value = cmd.Parameters(0)


    but this only give me my first input parameter and I looped through the parameter list and it is only listing my input/output parameters, not the value from the RETURN command.

    So, my question is ... is it even possible get the value from the RETURN command when I am sending parameters?  Or should I just stop trying and create a 2nd OUTPUT parameter and put the return value in there?

    Thursday, February 3, 2011 4:41 PM

Answers

  • User312496708 posted

    Add a parameter to the command, using ParameterDirection.ReturnValue. The return value will be present in the paramter after the execution.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 4:59 PM
  • User2004711764 posted

    Set parameter direction to ReturnValue.


    Morzel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 5:07 PM

All replies

  • User312496708 posted

    Add a parameter to the command, using ParameterDirection.ReturnValue. The return value will be present in the paramter after the execution.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 4:59 PM
  • User2004711764 posted

    Set parameter direction to ReturnValue.


    Morzel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 3, 2011 5:07 PM
  • User-1830216367 posted

    thanks guys ... duh ... don't know how I missed that.


    Thursday, February 3, 2011 8:57 PM