CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
Working with DataTables
The DataTable type defines many members, many of which are identical in name and functionality to
those of the DataSet. Table 22-7 describes some core members of the DataTable type beyond Rows and
Columns.
Table 22-7. Key Members of the DataTable Type
Member
Meaning in Life
CaseSensitive
Indicates whether string comparisons within the table are case sensitive. The
default value is false.
ChildRelations
Returns the collection of child relations for this DataTable (if any).
Constraints
Gets the collection of constraints maintained by the table.
Copy()
A method that copies the schema and data of a given DataTable into a new
instance.
DataSet
Gets the DataSet that contains this table (if any).
DefaultView
Gets a customized view of the table that might include a filtered view or a cursor
position.
ParentRelations
Gets the collection of parent relations for this DataTable.
PrimaryKey
Gets or sets an array of columns that function as primary keys for the data table.
TableName
Gets or sets the name of the table. This same property might also be specified as
a constructor parameter.
To continue with the current example, you can set the PrimaryKey property of the DataTable to the
carIDColumn DataColumn object. Be aware that the PrimaryKey property is assigned a collection of
DataColumn objects to account for a multicolumned key. In this case, however, you need to specify only
the CarID column (being the first ordinal position in the table), like so:
static void FillDataSet(DataSet ds)
{
...
// Mark the primary key of this table.
inventoryTable.PrimaryKey = new DataColumn[] {