Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

SqlCommand.ExecuteScalar won't return RETURN?

Currently I have a stored procedure that does X, but all I'm interested right now is having it return different return codes (integers).. so I figure I can use the SQL RETURN method which allows you to return an integer.

But when I use the SqlCommand object and call ExecuteScalar(), shouldn't it return my integer from RETURN? Or it just doesn't work that way? And if not, then what?

Victor Vuong
Saturday, December 21, 2002

I figured it out. What you need to do is still have parameter added to your SqlCommand with the type as return value. Then whatever you did in RETURN will be set to that for you to get the value.

Victor Vuong
Sunday, December 22, 2002

Or simply add the following line as the last statement
in your stored procedure:

select @xxx = @your_return_value_variable

(assuming T-SQL).

DataReader returns the first field in the first row of the
resultset, so this should do the trick. The '@xxx' can be
anything you want.

Monday, December 23, 2002

*  Recent Topics

*  Fog Creek Home