NextResult
Boolean moreResultSets = DataReader.NextResult();
Moves the reader to the next result set. A
DataReader
returns multiple result sets only if
you use a batch query or if you invoke a stored procedure that
includes more than one SELECT query. By default, the
DataReader
begins on the first result set.
NextResult( )
returns true
if
there are more result sets.
Here’s an example that retrieves multiple result sets using a batch query:
// Define a batch query. string SQL = "SELECT * FROM Categories; SELECT * FROM Products"; SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(SQL, con); con.Open(); // Execute the batch query. SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // (Process the category rows here.) } reader.NextResult(); while (reader.Read()) { // (Process the product rows here.) }