This topic is locked
[SOLVED]

 Assign value returned by stored procedure to varible

12/2/2014 12:47:35 PM
ASPRunner.NET General questions
T
Tim author

Hello,
In the "Before record updated" event on an Edit page I execute a stored procedure, which does some work and returns a single number. Is it possible to grab that and assign it to a session variable? Something like:
XSession.Session["ReturnNum"] = StoredProcedureOutput
Thanks,

Tim

admin 12/3/2014

This should be possible and you can find the sample code at http://stackoverflow.com/questions/3433694/how-to-run-the-stored-procedure-that-has-output-parameter-from-c
Most likely you will have to open a separate database connection for this purpose.

T
Tim author 12/6/2014

Thanks for the reply and link. I actually figured out how to do what I needed and it was pretty straight forward. I am using MSSQL 2008 and this is what I did in ASPRunner:

string sql = "DECLARE @return_value int EXEC @return_value = MyStoredProc " + values["PassValue"].ToString() + " SELECT 'return' = @return_value";

XVar rs = tDAL.CustomQuery(sql);

XVar data = CommonFunctions.db_fetch_array(rs);


And then I can access the returned value like so:

XSession.Session["ReturnNum"] = data["return"];


This is really helpful and I think I'll be using it a lot.

Thanks,

Tim