Retrieving output parameters with ExecuteReader() instead ofExecuteNonQuery

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.
 
M

msch.prv

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.
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top