Share via


Walkthrough: Using a DbDataReader to Retrieve Multiple Rows

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

This walkthrough demonstrates how to use a DbDataReader to retrieve multiple rows of data.

To reproduce the demonstration

  1. Configure the database. For the necessary steps, see "QuickStart Configuration" in Data Access QuickStart.
  2. Create the database (when you are not using the Unity Integration approach). In the following code, the factory creates a Database object that has the default configuration.
  3. Create the command by adding the following code. It creates a DbCommand used with a SQL String.
  4. Call ExecuteReader by adding the following code, which passes the DbCommand for the SQL command text used to populate the DbDataReader.
  5. Process the results by adding the following code inside the using statement, which loops through the DbDataReader and places the results into a string.
  6. If the DbDataReader was not scoped with a using statement, add the following code to explicitly close the DbDataReader.