SqlDataReader can be used if you want to keep an open connection to the database and use the rows as they come to you (forward only stream of data).
When you use SqlHelper.ExecuteDataSet, what happens is it serializes the data to XML and returns it to you at the end of
the GET operation. However, with SqlDataReader, you get the rows as they come, which can be handy if there is a lot of
rows (say, millions), or if you have some sort of parallel processing you want to do while the data is still coming.
Here is an example of how to use SqlDataReader. Take a look below for an example, uses both SqlCommand and then
the Microsoft Application Blocks version
Download the source code for the below example
While Microsoft provides you with the Microsoft ApplicationBlock class to make your database-driven application development easier, occasionally, you may have to use .NET’s built-in SqlReader class to connect to a database.
Using SqlReader is quite simple–you feed it a connection string and a query, then pull fields and use readerInstance.Read() to advance row-by-row.
First, set up your application with the appropriate settings, including the connection to the database: