Differences between dataadapter and datareader in C #

Source: Internet
Author: User
ADO. NET provides the following two objects for retrieving relational data and storing it in memory: DataSet AndDatareader. DataSetProvides a relational representation of data in the memory, a set of data including some tables (these tables contain data, sort the data and constrain the data), and the relationship between tables. Datareader provides a fast, forward-only, read-only data stream from the database.
When using DataSetDataadapter (or commandbuilder) is often used to interact with the data source. When using DataSetYou can also use dataview DataSetData Application sorting in AndFilter. You can also DataSetInherit, create a strong type DataSetUsed to split tables and rows AndColumns are published as strong object attributes.
When designing an application, consider the level of functionality required by the application to determine the use DataSetOr datareader.
Use DataSet:
R is used to navigate between multiple discrete tables in the result.
R operations come from multiple data sources (for example, from multiple databases and an XML file) AndData of a workbook.
R exchanges data between layers or uses XML Web Services. Unlike datareader, DataSetCan be passed to the remote client.
R reuse the same set of records to improve performance (such as sorting, searching, or filtering data) through caching ).
R each record requires a large amount of processing. Extended processing of each row returned by datareader will prolong the necessary time to serve the datareader connection, which affects the performance.
R uses XML operations to operate data, such as extensible style sheet language conversion (XSLT conversion) or XPath query.

Use DataReader in applications in the following cases:
R does not need to cache data.
The result set to be processed by r is too large to be stored in the memory.
Once r needs to access data in a forward-only and read-only manner.
Note FillingDataSetThe DataAdapter uses DataReader. Therefore, use DataAdapter to replaceDataSetThe performance is reduced.DataSetMemory usageAndFillDataSetLoop. Generally, this performance improvement is symbolic. Therefore, design decisions should be based on the required functions.

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.