Export (0) Print
Expand All

Key Scenarios

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 topic describes the most common situations developers must address when accessing a database. Each scenario explains the task, describes a real-world situation where such a task might arise, and includes code demonstrating how to use the Data Access Application Block to complete the task. The scenarios are as follows:

  • Using a DbDataReader to Retrieve Multiple Rows. This scenario illustrates how you can use the ExecuteReader method to retrieve multiple rows of data from a database for display in tabulated form—without explicitly caching the data, using a DataSet object to manipulate it, or passing it to other components within your application. In other words, it illustrates how to display the results as quickly as possible.
  • Using a DataSet to Retrieve Multiple Rows. This scenario illustrates how you can use the ExecuteDataSet method to pass data between the components and the tiers of a multi-tier application. The data consists of one or more data tables and, optionally, the relationships that link the tables together.
  • Executing a Command and Accessing Output Parameters. This scenario illustrates how you can use the ExecuteNonQuery method to retrieve a single row that contains multiple column values.
  • Executing a Command and Accessing a Single-Item Result. This scenario illustrates how you can use the ExecuteScalar method to perform a single-item lookup.
  • Performing Multiple Updates Within a Transaction. This scenario illustrates how you can use the ExecuteNonQuery method from within a transaction to perform multiple operations against a database, where it is essential that either all operations succeed or none succeed.
  • Using a DataSet to Update a Database. This scenario illustrates how, after changing a DataSet object, you can use the UpdateDataSet method to update the database and make your changes permanent.
  • Retrieving Multiple Rows as XML. This scenario illustrates how you can use the ExecuteXmlReader method to retrieve data from a SQL Server and have that data returned in XML format.

This document does not help you choose the correct approach for your particular situation (for example, it does not help you choose between a DataSet and a DbDataReader). Instead, it helps you implement your approach by using the Data Access Application Block. For guidance on approaches to data access, see the following Microsoft patterns & practices guides:

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.
Show:
© 2014 Microsoft