Defining the Schema of a DataTable

The schema, or structure, of a table is represented by columns and constraints. You define the schema of a DataTable using DataColumn objects as well as ForeignKeyConstraint and UniqueConstraint objects. The columns in a table can map to columns in a data source, contain calculated values from expressions, automatically increment their values, or contain primary key values.

Case Sensitivity

References by name to columns, relations, and constraints in a table are case-sensitive. Two or more columns, relations, or constraints can exist in a table that have the same name, but that differ in case. For example you can have Col1 and col1. In this situation a reference to one of the columns by name must match the case of the column name exactly, otherwise an exception is thrown. For example, if the table myTable contains the columns Col1 and col1, you would reference Col1 by name as myTable.Columns["Col1"], and col1 as myTable.Columns["col1"]. Attempting to reference either of the columns as myTable.Columns["COL1"] would generate an exception.

The case-sensitivity rule does not apply if only one column, relation, or constraint exists with a particular name. That is, if no other column, relation, or constraint object in the table matches the name of that particular column, relation, or constraint object, even by a difference in case, you may reference the object by name using any case and no exception is thrown. For example, if the table has only Col1, you can reference it using my.Columns["COL1"].

The CaseSensitive property of the DataTable does not affect this behavior. The CaseSensitive property applies to the data in the table and affects sorting, searching, filtering, enforcing constraints, and so on. References to the columns, relations, and constraints in a table are not affected by the CaseSensitive property.

In This Section