SqlDataReader with multiple result sets
-
When I execute a stored procedure with SqlCommand.ExecuteReader, how do I access the specific result set I need in the case that the stored procedure returns more than one result set?
The difficult we do right away... ...the impossible takes slightly longer.
-
When I execute a stored procedure with SqlCommand.ExecuteReader, how do I access the specific result set I need in the case that the stored procedure returns more than one result set?
The difficult we do right away... ...the impossible takes slightly longer.
My understanding of this is you can use
NextResult
to get the next resultset. As it's a firehose, you can't go backwards unfortunately. -
My understanding of this is you can use
NextResult
to get the next resultset. As it's a firehose, you can't go backwards unfortunately.Thanks, Pete!
The difficult we do right away... ...the impossible takes slightly longer.
-
When I execute a stored procedure with SqlCommand.ExecuteReader, how do I access the specific result set I need in the case that the stored procedure returns more than one result set?
The difficult we do right away... ...the impossible takes slightly longer.
As Pete says, the reader doesn't "rewind" - so I'd probably prefer to use a DataAdapter and fill a Dataset instead of using a DataReader. That way all of the data for all of the sets is available for random access as needed.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
As Pete says, the reader doesn't "rewind" - so I'd probably prefer to use a DataAdapter and fill a Dataset instead of using a DataReader. That way all of the data for all of the sets is available for random access as needed.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Good point, Griff! I didn't know that option existed!
The difficult we do right away... ...the impossible takes slightly longer.