Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-02-27 : 09:28:32
|
Raymond writes "Given that I use IDbCommand dbCommand = new SqlCommand("storedProcName") ... and dbCommand.ExecuteNonQuery(); to run the stored procedure and it ends with the statement: RETURN 27 (for example)...There appears to be no possible way to get the returned value of 27 from the dbCommand .. True or false ? Our application has a number of existing stored procedures that indicate an error by using "RETURN" statements as opposed to "OUTPUT" parameters.. I'd like to avoid hacking over someone else's stored procedure code and numerous application sources to create "OUTPUT" parameters.." |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-02-27 : 14:00:29
|
I haven't tested it, but after some googling I found this:http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=809206&SiteID=17From the last post on that page (again, not tested):quote: You must add a SqlParameter like this to your command object:SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);returnValue.Direction = ParameterDirection.ReturnValue;After executing the command with e.g. ExecuteNonQuery(); you can get the return value of the stored procedure withint returnV = (int)returnValue.Value;Best regards
- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
|
|
|