Using DataReader, Datasets, DataAdapter, and DataView

Source: Internet
Author: User
Tags web services
Using DataReader, Datasets, DataAdapter, and DataView
Ado. NET provides two objects for retrieving relational data and storing it in memory, respectively, DataSet and DataReader. A dataset provides the performance of relational data in memory-a complete collection of data, including tables and orders, constraints, and relationships between tables. DataReader provides fast, forward-only, read-only data streams from the database.
When using a dataset, you typically use DataAdapter (or possibly CommandBuilder) to interact with the data source, sorting and filtering the data in the DataSet with DataView. The dataset can be inherited to create a dataset of the hardening type that exposes the table, row, and column as the object attribute of the hardening type.
The following content includes when to use Datasets or DataReader, and how to optimize access to the data they contain, as well as how to optimize the use of DataAdapter and DataView (also including CommandBuilder).
Comparison of DataSet and DataReader
When designing an application, deciding whether to use a dataset or DataReader requires consideration of the functionality required by your application.
The dataset is used to implement the following functions of the application:
L multiple detached tables in the result of the operation.
L manipulate data from multiple sources, such as mixed data from multiple databases, XML files, and spreadsheets.
L Exchange data between layers or use XML Web services. Unlike DataReader, a dataset can be passed to a remote client.
L Use the same rowset repeatedly to improve performance (such as sorting, searching, or filtering data) through buffering.
L Perform a large amount of processing per line. Extending processing on rows returned using DataReader will make the connection longer than necessary to reduce efficiency.
L Maintain data using XML operations such as XSLT transformations and XPath queries.
Use DataReader when your application requires the following features:
L Do not need buffered data.
L The result set being processed is too large to be put in memory.
L need to access the data quickly and in a forward-only read-only manner.
Note: When populating a DataSet, DataAdapter uses DataReader. Thus, the performance of using DataAdapter instead of a dataset saves the memory that the dataset consumes and the cycles required to assemble the dataset. Most of this performance improvement is nominal, so you should make design decisions based on the functionality you need.
Benefits of using a strongly typed dataset
Another benefit of using a dataset is that it can be inherited to create a strongly typed DataSet. The benefits of a strongly typed dataset include design-time checks and visual Studio for strongly typed datasets. NET statement fill. When you fix an outline or relational structure for a dataset, you can create a strongly typed DataSet, which takes rows and columns as attributes of an object rather than as a collection of items. For example, you can expose the Name property of the customer object as a substitute for the column names that expose a row of the Customers table. A strongly typed DataSet is derived from the DataSet class and therefore does not sacrifice any functionality of the dataset, that is, a strongly typed dataset can also be remote and provided as a data source for a data-bound control such as a DataGrid. If you don't know the outline, you can also benefit by using a regular dataset, but lose the additional attributes of a strongly typed DataSet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.