How to Multiple Result Sets in ADO.NET
The DataReader Object in ADO.NET provides a stream-based, forward-only, read-only retrieval of query results from the Data Source. It is specifically designed for retrieving data and does not allow for data modification operations.
When the ExecuteReader method is executed in the SqlCommand Object, it instantiates a SqlClient.SqlDataReader Object, which represents the result set obtained from the execution of the SQL statement.
In certain scenarios, there might be a need to execute multiple SQL statements and retrieve multiple result sets. In such cases, the SqlDataReader Object is capable of returning multiple ResultSets. This can occur when a batch of SQL statements is executed or when a stored procedure generates multiple result sets.
NextResult()
To handle these multiple ResultSets, the SqlDataReader provides a method called NextResult(). This method allows you to advance to the next ResultSet within the SqlDataReader Object. By calling NextResult(), you can move to the next set of results, if available.
Each time NextResult() is invoked, the SqlDataReader moves to the next ResultSet and makes it available for reading. This enables you to access the subsequent set of results, retrieve data from it, and perform any necessary operations. The NextResult() method returns a boolean value, indicating whether there are more ResultSets available or not.
In the following source code demonstrating how to get multiple result sets from SqlDataReader() .
Full Source VB.NETConclusion
The SqlDataReader Object in ADO.NET provides a means of retrieving query results from a Data Source. It is capable of handling multiple ResultSets, and the NextResult() method allows you to move from one ResultSet to another. This functionality proves useful in scenarios where multiple SQL statements or stored procedures are executed, resulting in multiple sets of data to be retrieved and processed.
- ADO.NET Connection Object
- ADO.NET SQL Server Connection
- ADO.NET OLEDB Connection
- ADO.NET ODBC Connection
- ADO.NET Command
- ADO.NET ExecuteNonQuery in SqlCommand Object
- ADO.NET ExecuteNonQuery in OleDbCommand Object
- ADO.NET ExecuteScalar in SqlCommand Object
- ADO.NET ExecuteScalar in OleDbCommand Object
- ADO.NET ExecuteReader in SqlCommand Object
- ADO.NET ExecuteReader in OleDbCommand Object
- How to ADO.NET DataReader
- How to ADO.NET SqlDataReader
- How to ADO.NET OleDbDataReader
- Getting Schema Informations from SqlDataReader
- Getting Schema Informations from OleDbDataReader
- What is DataAdapter
- What is SqlDataAdapter
- What is OleDbDataAdapter
- Vb.NET ExecuteReader and ExecuteNonQuery