A DataSet object represents an in-memory cache of data. It contains a collection of tables and knowledge of relationships between those tables. Each table contains a collection of columns. These objects represent the schema of the DataSet. Each table can then have multiple rows, representing the data held by the DataSet. These rows remember their original state along with their current state, so that the DataSet tracks what kinds of changes have occurred. Additionally, the DataSet provides persistence and de-persistance through XML.
The DataSet can be considered the centerpiece of ADO+, as it represents a complete set of data including multiple, related tables, and constraints. The DataSet thus provides a rich object model to work with when passing data between various components of an enterprise solution. For example, in a typical solution, a client application requests data through a URL. When the request arrives at an appropriate middle tier component, a DataSet is created using an adapter. The DataSet is then converted into an XML document for transport back to the requester. On the client application, the data is displayed using a combination of controls, such as the DataGrid. The user can manipulate the data—adding, deleting, and editing—to his or her satisfaction. When ready, the DataSet is again converted into an XML document for transmission back to the server component. The component converts the XML document back into a DataSet, and uses an adapter to attempt to merge the changed data back into the DBMS. If any collisions occur, the server component can reconcile them using built-in business rules. The reconciled DataSet is then returned back to the client. The DataSet can then be merged back into the existing DataSet, and the user can resume working with the DataSet that reflects the latest version.
There are two general ways to employ a DataSet. You can programmatically create a DataSet and add DataTable objects to it, then create DataRelation objects to link each table. Use the programmatic method when you need to create a DataSet at run time to capture data generated by an application.
Alternatively, you can use an existing DBMS, such as SQLServer, to fill tables in the DataSet. In this method, use one SQLDataSetAdapter per table to fill the DataTable object with data. You must, however, create the DataRelation objects between each table.
To use the DataSet you must include System.Data:
using System.Data