C# Multiple Result Sets
The DataReader Object in C# provides a stream-based, forward-only, read-only retrieval of query results from the Data Source without the ability to update the data.
When the ExecuteReader() method is invoked on the SqlCommand Object, it instantiates a SqlClient.SqlDataReader Object in C#. This SqlDataReader Object allows you to efficiently read and access the retrieved data from the Data Source.
In certain scenarios, there may be a need to execute multiple SQL statements using the same Command Object. In such cases, the SqlDataReader can handle multiple ResultSets. Each ResultSet represents the result of an individual SQL statement within the batch executed.
To retrieve multiple ResultSets from the SqlDataReader, you can use the NextResult() method. After reading the first ResultSet, invoking the NextResult() method advances the SqlDataReader to the next ResultSet, if available. This allows you to sequentially access the data from each ResultSet within the SqlDataReader.
By utilizing the NextResult() method iteratively, you can navigate through all the ResultSets returned by the SqlDataReader and retrieve the corresponding data as needed.
In the following source code you can see how to get multiple result sets from SqlDataReader() .Full Source C#
The DataReader Object in C# provides a stream-based, forward-only, read-only retrieval of query results from the Data Source. The SqlDataReader instantiated by the ExecuteReader() method in the SqlCommand Object facilitates this data retrieval. In situations where multiple SQL statements are executed using the Command Object, the SqlDataReader can handle multiple ResultSets. The NextResult() method allows you to navigate between these ResultSets and retrieve data from each one.