Disconnected operations in ADO.NET consist of data access scenarios that don't require the maintenance of an open database connection while working with data. This contrasts with the connected operations discussed in the preceding article in this series, which utilize the DataReader and Command classes. The primary vehicle for working with disconnected operations is the DataSet; it allows us to connect to a data source, manipulate the DataSet offline, and later reconnect to update the data source when necessary (see Figure 1).
Figure 1 Disconnected operations in ADO.NET.
The DataSet has other capabilities as well: the ability to hold several tables' worth of data, accomplish by-value serialization across remoting boundaries, and convert to and from XML with full fidelity. In this article, we'll concentrate on the DataSet as well as its primary helper class, the DataAdapter.
To download a zip file containing the source files for this article, click here.
A Disconnected Database
The DataSet (see Figure 2) is a full-featured relational database in its own right. It has a multi-tabular object structure with columns, rows, constraints, and relationships. The columns have defined datatypes with auto-increment value and calculated expression value support. The table can enforce unique or foreign key constraints, along with having a primary key to uniquely identify a row. Tables are linked together via relationships and foreign key constraints to help navigate quickly and effortlessly from parent to child row, as well as performing specific actions when data is modified. The row collections hold the data and allow the user to move forward and backward without worrying about a cursor model.
Figure 2 DataSet structure.