Two objects are provided for retrieving relational data and storing it in memory, namely DataSet and DataReader. DataSet provides the representation of relational data in memory - a complete data set including tables and relationships between tables such as order and constraints. DataReader provides fast, forward-only, read-only data flow from the database.
When using DataSet, DataAdapter (or maybe CommandBuilder) is generally used to interact with the data source, and DataView is used to sort and filter the data in the DataSet. DataSet can be inherited to create a DataSet of a harden type, which is used to expose tables, rows, and columns as harden type object properties.
The following content includes when to use DataSet 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 between DataSet and DataReader
When designing an application, deciding whether to use DataSet or DataReader requires consideration of the features required by the application.
DataSet is used to implement the following functions of the application:
l Multiple separate tables in the operation result.
2 Manipulate data from multiple sources (such as mixed data from multiple databases, XML files, and spreadsheets).
3 Exchange data between layers or use XML Web services. Unlike DataReader, DataSet can be passed to remote clients.
4 Reuse the same set of rows by buffering to improve performance (such as sorting, searching, or filtering data).
5 Perform a lot of processing per line. Extended processing on rows returned with DataReader will cause the connection to exist longer than necessary, thus reducing efficiency.
6 Use XML operations such as XSLT transformations and Xpath queries to maintain data.
Use DataReader when the application requires the following features:
l No buffering is required.
2 The result set being processed is too large to be put into memory.
3. The data needs to be accessed quickly and read-only with forward-only mode.
Note: When populating DataSet, DataAdapter uses DataReader. Therefore, the performance obtained by using DataAdapter instead of DataSet saves the memory consumed by DataSet and the cycles required to assemble DataSet. Most of this performance improvement is in name only, so you should make design decisions based on the required features.
Benefits of using strongly typed DataSet
Another benefit of using DataSet is that it can be inherited for creating strongly typed DataSets. The benefits of strongly typed DataSet include design-time checking and Visual Studio .NET statement filling of strongly typed DataSet. When you fix an outline or relational structure for DataSet, you can create a strongly typed DataSet, taking rows and columns as attributes of objects rather than collections of items. For example, instead of exposing the column name of a row in a customer table, you can expose the Name property of the Customer object. Strongly typed DataSet is derived from the DataSet class, so it does not sacrifice any functionality of the DataSet, that is, strongly typed DataSet can also be remote and provided as a data source for data binding controls such as DataGrid. If you don't know the outline, you can also gain benefits by using the usual DataSet, but lose the strong type
Additional features of DataSet
Handling empty values in strongly typed DataSet
When using a strongly typed DataSet, you can annotate the DataSet XML outline definition language (XSD) to ensure that the strongly typed DataSet correctly handles null references. The nullValue comment allows you to replace DBNull with this specific value, keep a null reference, or generate an exception. Select which of them depends on the content of the application, by default, encountering an empty reference will generate an exception.
Refresh data in DataSet
If you want to refresh the value in the dataset from the server using the updated value, use. If the primary key is defined on the data table, match the new row based on the primary key and change the server's data to the existing row. The RowState of the refreshed row is set to Unchanged, even if it was modified before refreshing. Note that if a primary key is defined for the data table, adding a new row may repeat the primary key value.
If you want to refresh a table with the current value of the server and keep the rows in the table changed, you must first combine it, populate a new data table, then merge the data table into a data set, and set the preserveChanges value to true.
Search for data in DataSet
Using index-based viewing tables will improve performance when querying rows that meet certain criteria in a dataset. When a primary key (PrimaryKey) value is assigned to the data table, an index is created. Indexes are also created when a data view (DataView) is created for a data table. Here are some tips for using index-based viewing:
If the query is performed on the primary key column of the data table, use instead.
Querying non-primary key columns allows you to use data views to increase the speed of multiple data queries. When adding sorts to the data view, the index used for search is created. The data view exposes the Find and FindRows methods for querying the lower data table.
If you are not a sorted view of the query table, you can also get the benefits of index-based viewing tables by creating a data view for the data table. Note that this is the only benefit if you execute multiple queries on the data. If you only execute a single query, the process that needs to create an index will degrade performance because of using the index.
DataView structure
When the data view is established, and when Sort, Ro
Using DataReader, DataSet, DataAdapter, and DataView
Two objects are provided for retrieving relational data and storing it in memory, namely DataSet and DataReader. DataSet provides the representation of relational data in memory - a complete data set including tables and relationships between tables such as order and constraints. DataReader provides fast, forward-only, read-only data flow from the database.
When using DataSet, DataAdapter (or maybe CommandBuilder) is generally used to interact with the data source, and DataView is used to sort and filter the data in the DataSet. DataSet can be inherited to create a DataSet of a harden type, which is used to expose tables, rows, and columns as harden type object properties.
When using DataSet, DataAdapter (or maybe CommandBuilder) is generally used to interact with the data source, and DataView is used to sort and filter the data in the DataSet. DataSet can be inherited to create a DataSet of a harden type, which is used to expose tables, rows, and columns as harden type object properties.
The following content includes when to use DataSet 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 between DataSet and DataReader
When designing an application, deciding whether to use DataSet or DataReader requires consideration of the features required by the application.
DataSet is used to implement the following functions of the application:
l Multiple separate tables in the operation result.
2 Manipulate data from multiple sources (such as mixed data from multiple databases, XML files, and spreadsheets).
3 Exchange data between layers or use XML Web services. Unlike DataReader, DataSet can be passed to remote clients.
4 Reuse the same set of rows by buffering to improve performance (such as sorting, searching, or filtering data).
5 Perform a lot of processing per line. Extended processing on rows returned with DataReader will cause the connection to exist longer than necessary, thus reducing efficiency.
6 Use XML operations such as XSLT transformations and Xpath queries to maintain data.
Use DataReader when the application requires the following features:
l No buffering is required.
2 The result set being processed is too large to be put into memory.
3. The data needs to be accessed quickly and read-only with forward-only mode.
Note: When populating DataSet, DataAdapter uses DataReader. Therefore, the performance obtained by using DataAdapter instead of DataSet saves the memory consumed by DataSet and the cycles required to assemble DataSet. Most of this performance improvement is in name only, so you should make design decisions based on the required features.
Benefits of using strongly typed DataSet
Another benefit of using DataSet is that it can be inherited for creating strongly typed DataSets. The benefits of strongly typed DataSet include design-time checking and Visual Studio .NET statement filling of strongly typed DataSet. When you fix an outline or relational structure for DataSet, you can create a strongly typed DataSet, taking rows and columns as attributes of objects rather than collections of items. For example, instead of exposing the column name of a row in a customer table, you can expose the Name property of the Customer object. Strongly typed DataSet is derived from the DataSet class, so it does not sacrifice any functionality of the DataSet, that is, strongly typed DataSet can also be remote and provided as a data source for data binding controls such as DataGrid. If you don't know the outline, you can also gain benefits by using the usual DataSet, but lose the strong type
Additional features of DataSet
Handling empty values in strongly typed DataSet
When using a strongly typed DataSet, you can annotate the DataSet XML outline definition language (XSD) to ensure that the strongly typed DataSet correctly handles null references. The nullValue comment allows you to replace DBNull with this specific value, keep a null reference, or generate an exception. Select which of them depends on the content of the application, by default, encountering an empty reference will generate an exception.
Refresh data in DataSet
If you want to refresh the value in the dataset from the server using the updated value, use. If the primary key is defined on the data table, match the new row based on the primary key and change the server's data to the existing row. The RowState of the refreshed row is set to Unchanged, even if it was modified before refreshing. Note that if a primary key is defined for the data table, adding a new row may repeat the primary key value.
If you want to refresh a table with the current value of the server and keep the rows in the table changed, you must first combine it, populate a new data table, then merge the data table into a data set, and set the preserveChanges value to true.
Search for data in DataSet
Using index-based viewing tables will improve performance when querying rows that meet certain criteria in a dataset. When a primary key (PrimaryKey) value is assigned to the data table, an index is created. Indexes are also created when a data view (DataView) is created for a data table. Here are some tips for using index-based viewing:
If the query is performed on the primary key column of the data table, use instead.
Querying non-primary key columns allows you to use data views to increase the speed of multiple data queries. When adding sorts to the data view, the index used for search is created. The data view exposes the Find and FindRows methods for querying the lower data table.
If you are not a sorted view of the query table, you can also get the benefits of index-based viewing tables by creating a data view for the data table. Note that this is the only benefit if you execute multiple queries on the data. If you only execute a single query, the process that needs to create an index will degrade performance because of using the index.
DataView structure
When the data view is established, and when Sort, Ro
Using DataReader, DataSet, DataAdapter, and DataView
Two objects are provided for retrieving relational data and storing it in memory, namely DataSet and DataReader. DataSet provides the representation of relational data in memory - a complete data set including tables and relationships between tables such as order and constraints. DataReader provides fast, forward-only, read-only data flow from the database.
When using DataSet, DataAdapter (or maybe CommandBuilder) is generally used to interact with the data source, and DataView is used to sort and filter the data in the DataSet. DataSet can be inherited to create a DataSet of a harden type, which is used to expose tables, rows, and columns as harden type object properties.