Retrieving output parameters with ExecuteReader() instead ofExecuteNonQuery

  • Thread starter Thread starter msch.prv
  • Start date Start date
M

msch.prv

Hi, I just wonder if it is possible to retrieve sproc output
parameters with the ExecuteReader() method. I have some code that
works fine with the ExecuteNonQuery() variant, but fails with the
reader approach.

An article on 4 Guys by Scott Mitchell:
http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/062905-1.aspx
seems to suggest this is feasible. For some reason, I cannot run
these examples: the output parameters return nothing. When
ExecuteNonQuery() is substituted back, parameter retrieving works.

Has anyone successfully used the ExecuteReader appproach to extract
output parameters? TIA for any pointers.
 
Ok, I found the error. Sproc output parameters can be extracted with
ExecuteReader(). However, the SqlDataReader must be closed before the
output parameters can be retrieved.
 
it doesn't need to be closed, you just need to read all result sets
before accessing the parameters, as their values come after the last
result set. calling close process all result sets.

-- bruce (sqlwork.com)
 
Back
Top