SqlCommand and RETURN value

  • Thread starter Thread starter John Grandy
  • Start date Start date
J

John Grandy

for a SqlCommand that corresponds to a SQL Server Stored Procedure that
inserts a row and uses RETURN to assign @@IDENTITY to the SP's return value
....

after performing

SqlCommand.ExecuteNonQuery()

how to retrieve the RETURN value ?
 
Or create a Command object to capture the Return value.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
for a SqlCommand that corresponds to a SQL Server Stored Procedure that
inserts a row and uses RETURN to assign @@IDENTITY to the SP's return value

after performing
SqlCommand.ExecuteNonQuery()

how to retrieve the RETURN value ?

You need to have added a parameter to your SqlCommand object, which
has its "Direction" property set to "ParameterDirection.ReturnValue".
Something like this:

SqlCommand1.Parameters.Add("@RETVAL", SqlDbType.INT).Direction =
ParameterDirection.ReturnValue;

After you've called your .ExecuteNonQuery, you should be able to
easily read out your return value:

int iMyReturnValue = (int)SqlCommand1.Parameters["@RETVAL"].Value;

HTH
Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Back
Top