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.