15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Managing Data <strong>and</strong> relationships: The Dataset Class ❘ 835<br />

managing daTa <strong>and</strong> relaTionshiPs: The daTaseT Class<br />

The DataSet class has been designed as an offline container of data. It has no notion of database connections.<br />

In fact, the data held within a DataSet does not necessarily need to have come from a database — it could just<br />

as easily be records from a CSV file, an XML file, or points read from a measuring device.<br />

A DataSet class consists of a set of data tables, each of which will have a set of data columns <strong>and</strong> data<br />

rows (see Figure 30-4). In addition to defining the data, you can also define links between tables within<br />

the DataSet class. One common scenario would be defining a parent-child relationship (commonly<br />

known as master/detail). One record in a table (say Order) links to many records in another table (say<br />

Order_Details). This relationship can be defined <strong>and</strong> navigated within the DataSet.<br />

DataSet<br />

DataTable<br />

DataRow<br />

DataTable<br />

DataColumn<br />

figure 30-4<br />

It is important to remember that basically, the DataSet class is an in-memory database that includes all<br />

the tables, relationships, <strong>and</strong> constraints. The following sections describe the classes that are used with a<br />

DataSet class.<br />

data Tables<br />

A data table is very similar to a physical database table — it consists of a set of columns with particular<br />

properties <strong>and</strong> might have zero or more rows of data. A data table might also define a primary key, which<br />

can be one or more columns, <strong>and</strong> might also contain constraints on columns. The generic term for this<br />

information used throughout the rest of the chapter is schema.<br />

Several ways exist to define the schema for a particular data table (<strong>and</strong> indeed the DataSet class as a whole).<br />

These are discussed after introducing data columns <strong>and</strong> data rows. Figure 30-5 shows some of the objects<br />

that are accessible through the data table.<br />

DataTable<br />

Columns<br />

DataColumn<br />

Rows<br />

DataRows<br />

Constraints<br />

Constraint<br />

ExtendedProperties<br />

Object<br />

figure 30-5<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!