System.Data.DataColumn Class

Represents the schema of a column in a System.Data.DataTable.

See Also: DataColumn Members

Syntax

[System.ComponentModel.DesignTimeVisible(false)]
[System.ComponentModel.DefaultProperty("ColumnName")]
[System.ComponentModel.ToolboxItem(false)]
[System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Design.DataColumnEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class DataColumn : System.ComponentModel.MarshalByValueComponent

Remarks

The System.Data.DataColumn is the fundamental building block for creating the schema of a System.Data.DataTable. You build the schema by adding one or more System.Data.DataColumn objects to the System.Data.DataColumnCollection. For more information, see Adding Columns to a Table.

Each System.Data.DataColumn has a DataColumn.DataType property that determines the kind of data the System.Data.DataColumn contains. For example, you can restrict the data type to integers, or strings, or decimals. Because data that is contained by the System.Data.DataTable is typically merged back into its original data source, you must match the data types to those in the data source. For more information, see Mapping .NET Framework Data Provider Data Types to .NET Framework Data Types.

Properties such as DataColumn.AllowDBNull, DataColumn.Unique, and DataColumn.ReadOnly put restrictions on the entry and updating of data, thereby helping to guarantee data integrity. You can also use the DataColumn.AutoIncrement, DataColumn.AutoIncrementSeed, and DataColumn.AutoIncrementStep properties to control automatic data generation. For more information about DataColumn.AutoIncrement columns, see Creating AutoIncrement Columns. For more information, see Defining a Primary Key for a Table.

You can also make sure that values in a System.Data.DataColumn are unique by creating a System.Data.UniqueConstraint and adding it to the System.Data.ConstraintCollection of the System.Data.DataTable to which the System.Data.DataColumn belongs. For more information, see Adding Constraints to a Table.

To create a relation between System.Data.DataColumn objects, create a System.Data.DataRelation object and add it to the System.Data.DataRelationCollection of a System.Data.DataSet.

You can use the DataColumn.Expression property of the System.Data.DataColumn object to calculate the values in a column, or create an aggregate column. For more information, see Creating Expression Columns.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0