开发者

2 Resultsets in Datareader

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜