Is it not possible to get the return value of a stored procedeure when using a datareader? The return value is always null, but the SP returns a valid int from within SSMS.
myCommand.CommandText = "GetVenueVideos";
SqlParameter retVal = new SqlParameter("@returnValue",SqlDbType.Int);
retVal.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add(retVal);
myReader = myCommand.ExecuteReader();
if (myReader.Read() && myReader.HasRows)
{
int returnValue = Convert.ToInt32(retVal.Value);
//returnValue is null at this point
}
Agh. I’ve found out the reader has to be closed to get the return value! So inside the if {} block above, I added:
…and now it works OK!