G
Guest
I have a question regarding accessing a stored procedure's "return" value. Some of my SQL Server stored procedures return a result set. The only way I can see what the stored procedure return in the "return" value is by using the .ExecuteNonQuery command method. If I use the .ExecuteReader method the "return" value is always 0. My questions are
1. What is the syntax to see what the "return" value is from a stored procedure if I use the ExecuteReader method? (assuming I expect the sp to return a result set
2. What is the cost of performing both an ExecuteNonQuery (to get the return value) and ExecuteReader (to get the result set) on the same command object
Code examples
1. Using the ExecuteReader method that never returns the correct sp "return" value (I even changed the sp to always return a positive value)
set up the connection, command, et
command.Parameters.Add("@return", SqlDbType.Int
command.Parameters("@return").Direction = ParameterDirection.ReturnValu
connection.Open(
command.ExecuteReader(
If (command.Parameters("@return").Value = 0) Then '0 means no error, at this point even if I force the return value to 1 the If statement is always tru
2. Cost of using the .ExecuteNonQuery and .ExecuteReader() methods, this works but I'm concerned about cost and performance
set up the connection, command, et
command.Parameters.Add("@return", SqlDbType.Int
command.Parameters("@return").Direction = ParameterDirection.ReturnValu
connection.Open(
command.ExecuteNonQuery(
If (command.Parameters("@return").Value = 0) The
reader = command.ExecuteReader(
1. What is the syntax to see what the "return" value is from a stored procedure if I use the ExecuteReader method? (assuming I expect the sp to return a result set
2. What is the cost of performing both an ExecuteNonQuery (to get the return value) and ExecuteReader (to get the result set) on the same command object
Code examples
1. Using the ExecuteReader method that never returns the correct sp "return" value (I even changed the sp to always return a positive value)
set up the connection, command, et
command.Parameters.Add("@return", SqlDbType.Int
command.Parameters("@return").Direction = ParameterDirection.ReturnValu
connection.Open(
command.ExecuteReader(
If (command.Parameters("@return").Value = 0) Then '0 means no error, at this point even if I force the return value to 1 the If statement is always tru
2. Cost of using the .ExecuteNonQuery and .ExecuteReader() methods, this works but I'm concerned about cost and performance
set up the connection, command, et
command.Parameters.Add("@return", SqlDbType.Int
command.Parameters("@return").Direction = ParameterDirection.ReturnValu
connection.Open(
command.ExecuteNonQuery(
If (command.Parameters("@return").Value = 0) The
reader = command.ExecuteReader(