Followers

Monday, August 16, 2004

DataSet vs. DataReader

To determine whether to use the DataSet or the DataReader when you design your application, consider the level of functionality that is needed in the application.

Use the DataSet in order to do the following with your application:

Navigate between multiple discrete tables of results.
Manipulate data from multiple sources (for example, a mixture of data from more than one database, from an XML file, and from a spreadsheet).
Exchange data between tiers or using an XML Web service. Unlike the DataReader, the DataSet can be passed to a remote client.
Reuse the same set of rows to achieve a performance gain by caching them (such as for sorting, searching, or filtering the data).
Perform a large amount of processing per row. Extended processing on each row returned using a DataReader ties up the connection serving the DataReader longer than necessary, impacting performance.
Manipulate data using XML operations such as Extensible Stylesheet Language Transformations (XSLT transformations) or XPath queries.
Use the DataReader in your application if you:

Do not need to cache the data.
Are processing a set of results too large to fit into memory.
Need to quickly access data once, in a forward-only and read-only manner.
Note The DataAdapter uses the DataReader when filling a DataSet. Therefore, the performance gained by using the DataAdapter instead of the DataSet is that you save on the memory that the DataSet would consume and the cycles it takes to populate the DataSet. This performance gain is, for the most part, nominal so you should base your design decisions on the functionality required.

No comments: