Is it possible to store 2 or more resultsets in a Datareader? I have different methods which each return a DataReader. Can I store resultsets of them in the same DataReader? (I us开发者_JAVA技巧e vs 2008 )
Yes, send the query as below:
string select = "select * from Categories; select * from customers";
SqlCommand command = new SqlCommand ( select, conn );
conn.Open ();
SqlDataReader reader = command.ExecuteReader ();
You can use the two results:
do
{
while ( reader.Read () )
{
Console.WriteLine ( "{0}\t\t{1}", reader[0], reader[1] );
}
}while ( reader.NextResult () );
The inner while iterates over the individual records from a resultset; the NextResult() jumps to the next resultset.
精彩评论