Can SqlDataReader be used against stored procedures that return multiple resultsets?

  • Thread starter Thread starter Top Gun
  • Start date Start date
T

Top Gun

In order to avoid multiple trips to the database, I would like to fill
several tables in a DataSet with a single call to a stored procedure that
will return resultsets for the appropriate tables.

Can the SqlDataReader be used for this?
 
Technically you could, but you probably don't want to. If the db you are
using supports batch commands, you could seperate them withe a ';' for
instance, and have x number of SQL Statements exectuted together. WHen the
query returns, you'll have the same number of tables as queries. Similarly,
your proc could have multiple select statements in it and you'll get the
same effect. To answer your question about the Reader though, yes, you
could do it there too but it'd be a lot more work b/c you'd need to walk the
colums and rows collections of the reader and build each table...in order to
get to the next Select command, use DataReader.NextResult.

HTH,

Bill
 
Back
Top