INFO: Roadmap for ADO.NET DataSet, DataView, and DataViewManager Objects
Retired KB Content Disclaimer
Roadmap articles provide links to useful information, including onlinedocumentation, Microsoft Knowledge Base articles, and Microsoft white papers, to help you learn about a Microsoft product or technology. Microsoft Knowledge Base How To articles and walkthroughs provide step-by-step instructions to accomplish specific tasks. QuickStart sample files are ready-made programs that illustrate a technique.
For additional ADO.NET technology roadmap articles, click the article number below to view the article in the Microsoft Knowledge Base:
OverviewA DataSet is a disconnected data store that provides consistent functionality regardless of the data source. A DataSet also provides a bridge between relational organization of data (for example, a database) and hierarchical organization of data (for example, Extensible Markup Language).
The DataSet is similar to an array of disconnected Recordset objects, but the DataSet offers more powerful functionality. The DataSet can maintain local constraints, cascade updates and deletions, and provide hierarchical navigation along relations. The DataSet also has a more powerful expression evaluator than Microsoft ActiveX Data Objects (ADO). This provides more flexibility when you search for and filter records. The DataSet also allows low-level control over row versioning and error state.
A DataView provides a mechanism for sorting and filtering a single DataTable. A DataViewManager provides a mechanism for sorting and filtering multiple DataTable objects when you perform hierarchical navigation.
For more information about the ADO.NET DataSet object, refer to the following Microsoft Web site:
Database-like Data Containers
DataSetDataSet objects include the following elements:
- DataTable objects
- DataColumn objects
- DataRow objects
- DataRelation objects
- ExtendedProperties collection
The DataSet provides the functionality to read and to write Extensible Markup Language (XML) data and schema through the following methods:
The following list describes some of the methods and the properties of the DataSet:
- HasChanges property. This property returns True if any of the DataTable objects contain modified records.
- GetChanges method. This method returns a copy of the DataSet that contains only changed elements.
You can combine DataRowState flags to control whether you get added, deleted, or modified records (or a combination thereof). By default, all changes are returned. If no changes exist, null (in Microsoft Visual C# .NET, Microsoft Visual C++ .NET, Microsoft JScript .NET) or Nothing (in Microsoft Visual Basic .NET) is returned.
- Merge method. This method combines two DataSet objects. The MissingSchemaAction argument controls whether the target DataSet schema is extended to match the source DataSet schema, whether extended schema is ignored, or whether it causes an exception.
- If a primary key on a DataTable object exists, this key is used to update the target record from a record with the same key in the source DataSet. If no primary key exists, the records are appended, which results in duplicate records.
- If the PreserveChanges argument is True, only added records are merged (that is, any changes in the target DataSet are preserved). If the source DataSet contains modified records, the original key values are used to match records in the target DataSet.
- CaseSensitive property. This property determines whether data is case-sensitive, though this can also be set on a table-by-table basis. Schema is both case-sensitive and not case-sensitive. When ADO.NET accesses an item, ADO.NET uses a case-sensitive lookup. If this fails, ADO.NET uses a lookup that is not case-sensitive. If there is more than one item with the same name (that is not case-sensitive), you receive an exception if the case-sensitive lookup fails.
- AcceptChanges and RejectChanges methods. These methods locally commit or roll back data changes in the DataSet. These methods do not affect schema changes.
- Locale property. This property allows you to set a CultureInfo object to govern sorting and searching.
- DefaultViewManager property. This property returns a DataViewManager object that the DataSet maintains. You can manipulate this object for sorting and for filtering, or you can create one or more independent DataViewManager objects of your own.
Creating and Using DataSets
Creating a DataSet
Adding a DataTable to a DataSet
Adding a Relationship between Tables
Navigating a Relationship between Tables
Using a DataSet with Existing Data
Merging DataSet Contents
Copying DataSet Contents
Working with DataSet Events
These articles are from the Diving Into Data Access column.
Microsoft Knowledge Base How To Articles
DataTableA DataTable is a collection of metadata and data, where the metadata is described by a collection of DataColumn objects and Constraint objects, and the data is contained in a collection of DataRow objects. A DataTable may exist by itself or as part of a DataSet.
Unlike the ADO Recordset object, which manipulates a Provider, the DataTable is a passive object. The DataAdapter object, the XmlDataDocument object, and the user code manipulate the DataTable. The DataTable does not know where its own data comes from. This data can come from multiple sources.
The following list describes some of the methods and the properties of the DataTable:
- AcceptChanges method, RejectChanges method, Clone method, Copy method, GetChanges method, and HasChanges property. These methods and the HasChanges property operate similarly to their equivalents in the DataSet, except that they affect a single DataTable.
- PrimaryKey property. You can use the PrimaryKey property to indicate which column or columns make up the primary key.
- ImportRow method. This method adds a copy of a DataRow from another DataTable that has identical schema. You can use this method in conjunction with the Clone method to copy records more selectively than the Copy method.
- Select method. This method returns an array of DataRow objects that are sorted and filtered according to the arguments that you supply. You can also filter by row state.
- Constraints property. This property is a collection of unique constraints and foreign key constraints on the DataTable.
back to the top
DataColumnYou can use the DataColumn to define the attributes for a column in a DataTable or a DataRow (mainly the ColumnName and the DataType attributes). The DataColumn contains AutoNumber and Null support.
The following list describes some of the properties of the DataColumn:
- ColumnMapping property. This property controls whether the DataColumn object maps to an XML element or to an attribute when the XmlDataDocument manipulates the DataColumn or when the DataSet serializes the DataColumn.
- Unique property. This property allows you to set a unique constraint on a non-primary key column.
back to the top
DataRowAlthough a DataRow may exist by itself, the DataTable or the DataRowBuilder must create the DataRow. For example, you can use the NewRow method of the DataTable to create the DataRow, or you can use a DataTable for schema of the DataRowBuilder to create the DataRow.
The DataRow can have multiple states, including:
The DataRow can have multiple versions, including:
- Proposed (when you are editing)
The following list describes some of the methods and the properties of the DataRow:
- HasVersion method. You can test for a particular DataRowVersion value by using the HasVersion method.
- Deleted rows do not have a Current version.
- Added rows and detached rows do not have an Original version.
- If you are not within a BeginEdit, EndEdit, and CancelEdit block, the row does not have a Proposed version.
- GetParentRow, GetParentRows, GetChildRow, and GetChildRows methods. These methods return a DataRow object or an array of DataRow objects that contain parent or child rows based on the DataRelation that is named. These methods allow for hierarchical access between tables.
NOTE: The DataRelation object can allow many relations between tiers (that is, the DataRelation does not have to use unique columns). Therefore, the DataRow includes the GetParentRows method.
- HasErrors and RowError properties. These properties indicate whether the DataRow has an error. Although the DataAdapter usually sets these properties after an update fails, you can also set these properties manually.
DataRelationThe DataRelation object defines the parent/child relation between two DataTable objects.
The following list describes some of the properties of the DataRelation:
- ParentKeyConstraint and ChildKeyConstraint properties. These properties determine whether referential integrity is enforced.
- Nested property. This property determines whether child table elements are nested within the parent table when the DataSet is serialized to XML.
ExtendedPropertiesThe DataSet, the DataTable, the DataRelation, and the Constraint objects all support an ExtendedProperties collection where you can store user-defined attributes for that object.
back to the top
DataViewA DataView allows you to sort and filter records that you view. Each DataTable has a DefaultView object that you can access and set properties on. In addition, you can create a number of independent DataView objects on a DataTable. The DataView creates an index that is based on the sorted columns, which provides fast search capabilities through the Find method. This Find method only searches the current, sorted column. If the DataView is sorted on multiple columns, you must provide an array of values in the Find method.
You can edit the Current value of fields in a DataTable row by simple assignment. The change is immediate. Alternately, you can use the BeginEdit method to change Proposed row versions and use the EndEdit or the CancelEdit method to commit or roll back your changes.
You cannot directly edit data rows in the DataView. You must use the BeginEdit, the EndEdit, and the CancelEdit methods instead. After you call the EndEdit method, the changes are written to the DataTable and are available immediately. Other DataView objects on the same DataTable are notified of the changes.
By default, a DataView binds to the Current rows. You can pass a DataViewRowState to the constructor to bind to other row versions (for example, to access Deleted records).
NOTE: You can only bind a DataView to a single DataTable. You cannot make a DataView filter another DataTable after you create the DataView.
The ListChanged event is raised whenever the underlying filtered or sorted data is changed.
Visual Studio .NET Help Documentation
The following article is from the Diving into Data Access column.
Microsoft Knowledge Base Article
DataViewManagerIf you navigate to child records through a DataView or DataTable, the child records are unfiltered (except with regard to the parent records). The DataViewManager allows you to specify the RowFilter and the Sort properties that are applied when you perform hierarchical navigation.
For example, if you bind a Windows Form DataGrid control to a DataSet that contains a list of customers and orders, when you navigate to the orders for a particular customer, all orders are displayed. However, if you bind the DataGrid to a DataViewManager, and if you add a DataViewSetting object to the DataViewManager.DataViewSettings collection, you can filter the list of orders to display only those orders that exceed a certain monetary amount. In addition, you can filter the list of orders and sort them in descending order according to the order amount.
Visual Studio .NET Help Documentation
This article is from the Diving into Data Access column.
TroubleshootingIf you encounter problems and need answers to your questions, consult the MSDN newsgroups or the Microsoft Knowledge Base. In the MSDN newsgroups, you can share your experiences with your peers.
Searching the Knowledge Base
Article ID: 313485 - Last Review: 07/06/2012 17:19:00 - Revision: 7.0
- kbarttyperoadmap kbinfo kbsystemdata KB313485