You want to speed up read-only data access to a database in your application.
DataReader instead of a
DataAdapter to access the data.
Example 16-7 through Example 16-9 show the
.aspx file and
VB and C# code-behind files for our application that demonstrates the
performance difference between a
DataReader and a
DataAdapter using the
managed provider. Figure 16-2 shows the output of
the application. Refer to Recipe 16.4
for an equivalent example using the SQL Server managed provider.
Figure 16-2. Measuring data reader and data adapter performance output
The common language runtime (CLR) provides two primary methods for
reading data from a database. The first is to use a
DataReader, and the second is to use a
DataAdapter in conjunction with a
DataReader provides forward, read-only access
to the data read from the database. It provides no mechanisms for
randomly accessing the data.
DataAdapter, along with a
random access to data. In addition, the data can be changed in the
DataSet and the
DataAdapter can be used to update the data in the
Of the two access methods, the
DataReader is the
lightest and fastest and is preferable when you only need to read the
data, as reflected in the results we show for our sample application
in Figure 16-2 ...