views:

118

answers:

1

Hi,

Is it possible to store more than 2 resultsets in Datareader?I have different methods which returns datareader,can i store resultsets of them in the same datareader? (I use vs 2008 )

+1  A: 

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.

lmsasu
Thanks imsasu,i know this way but i have a question.I will have near 40 different resultsets and some of these resultset's queries are long.If i seperate these queries with ";",it can be difficult to debug when i come across a problem in sql query(Forexample in 23.resultset's query).Cant i do it by a different way?
Alexander
And also does it work for Oracle?
Alexander