System.Data.DataSet class
This article provides supplementary remarks to the reference documentation for this API.
The DataSet class, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects. For further details about working with DataSet objects, see DataSets, DataTables, and DataViews.
Whereas DataTable objects contain the data, the DataRelationCollection allows you to navigate though the table hierarchy. The tables are contained in a DataTableCollection accessed through the Tables property. When accessing DataTable objects, note that they are conditionally case sensitive. For example, if one DataTable is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. For more information about working with DataTable objects, see Creating a DataTable.
A DataSet can read and write data and schema as XML documents. The data and schema can then be transported across HTTP and used by any application, on any platform that is XML-enabled. You can save the schema as an XML schema with the WriteXmlSchema method, and both schema and data can be saved using the WriteXml method. To read an XML document that includes both schema and data, use the ReadXml method.
In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in turn, updating the original data are to:
Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter.
Change the data in individual DataTable objects by adding, updating, or deleting DataRow objects.
Invoke the GetChanges method to create a second DataSet that features only the changes to the data.
Call the Update method of the DataAdapter, passing the second DataSet as an argument.
Invoke the Merge method to merge the changes from the second DataSet into the first.
Invoke the AcceptChanges on the DataSet. Alternatively, invoke RejectChanges to cancel the changes.
Note
The DataSet and DataTable objects inherit from MarshalByValueComponent, and support the ISerializable interface for remoting. These are the only ADO.NET objects that can be remoted.
Note
Classes inherited from DataSet are not finalized by the garbage collector, because the finalizer has been suppressed in DataSet. The derived class can call the ReRegisterForFinalize method in its constructor to allow the class to be finalized by the garbage collector.
Security considerations
For information about DataSet and DataTable security, see Security guidance.