You want to speed up read-only data access to a database in your application.
DataReader instead of a
DataAdapter to access the data.
Examples 19-7, 19-8 through 19-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
OleDB managed provider. Figure 19-2 shows the output of the application. Refer to Recipe 19.4 for an equivalent example using the SQL Server managed provider.
The 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
Figure 19-2. Measuring data reader and data adapter performance output
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
DataSet, provides 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 database.
Of the two access methods, the
DataReader is the lightest and fastest and is preferable when you need to only read the data, as reflected in the results we show for our sample application in Figure 19-2. Our example reads 10KB ...