Pages

Monday, May 26, 2008

Differences between Dataset and DataReader

The Dataset object is central to supporting disconnected and distributed data scenarios with ADO.NET. The Dataset is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source. It can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application.

The Dataset represents a complete set of data including related tables, constraints, and relationships among the tables. I think this is something that gives the advantage upon the older ADO.

ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. Using the DataReader can increase application performance and reduce system overhead because only one row at a time is ever in memory.

Choosing a DataReader or a Dataset:

When deciding whether your application should use a DataReader (see Retrieving Data Using the DataReader) or a Dataset (see Creating and Using Dataset s), you should consider the type of functionality that your application requires.

Use a Dataset to do the following:

Remote data between tiers or from an XML Web service. Interact with data dynamically such as binding to a Windows Forms control or combining and relating data from multiple sources. Cache data locally in your application. Provide a hierarchical XML view of relational data and use tools like an XSL Transformation or an XML Path Language (XPath) Query on your data.
For more information, see XML and the Dataset . Perform extensive processing on data without requiring an open connection to the data source, which frees the connection to be used by other clients.

If you do not require the functionality provided by the Dataset . You can improve the performance of your application by using the DataReader to return your data in a forward-only read-only fashion. Although the DataAdapter uses the DataReader to fill the contents of a Dataset (see Populating a Dataset from a DataAdapter), by using the DataReader you can receive performance gains because you will save memory that would be consumed by the Dataset , as well as saving the processing required to create and fill the contents of the Dataset .

No comments: