A DataSet can contain either related or unrelated data. A DataSet can either have two unrelated tables, or two related tables. A DataSet can be thought of as a document of Data. In fact, an XML data document is like this, except it is based on a hierachical paradigm. Because data is often stored in relational databases, the DataSet can handle both hierachical relationships and key/foreign key relationships. Relationships can also have different types of enforcement. By default, deletions and updates are cascaded: if you delete a Customer Row, the related Orders rows are also deleted; if you Update the key of a Customer Row, the associated foreign key values in the Orders table is also updated.
<p>
A DataSet contains a Relations collection. It is easy to add a relationship to this collection using the column or columns (in a muli-column key) of the related tables. For example, imagine you have a DataSet with Customers and Orders data, and you want to create a relation between the two:
This code adds a relation between the CustomerId Key on the Customers table and the CustomerId foreign key on the Orders table in the DataSet. Now that a relationship exists, you can iterate through the data, using the relationship, in a meaningful way.
<p>
<div class=code>
<BR>foreach (DataRow Customer in dsCustomers.Tables["Customers"].Rows)