Represents the schema of a column in a DataTable.
Assembly: System.Data (in System.Data.dll)
The is the fundamental building block for creating the schema of a DataTable. You build the schema by adding one or more objects to the DataColumnCollection. For more information, see Adding Columns to a DataTable (ADO.NET).
Each has a DataType property that determines the kind of data the contains. For example, you can restrict the data type to integers, or strings, or decimals. Because data that is contained by the 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 Data Type Mappings in ADO.NET.
Properties such as AllowDBNull, Unique, and ReadOnly put restrictions on the entry and updating of data, thereby helping to guarantee data integrity. You can also use the AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties to control automatic data generation. For more information about AutoIncrement columns, see Creating AutoIncrement Columns (ADO.NET). For more information, see Defining Primary Keys (ADO.NET).
You can also make sure that values in a are unique by creating a UniqueConstraint and adding it to the ConstraintCollection of the DataTable to which the belongs. For more information, see DataTable Constraints (ADO.NET).
The following example creates a DataTable with several objects.
Private Sub MakeTable() ' Create a DataTable. Dim table As DataTable = new DataTable("Product") ' Create a DataColumn and set various properties. Dim column As DataColumn = New DataColumn column.DataType = System.Type.GetType("System.Decimal") column.AllowDBNull = False column.Caption = "Price" column.ColumnName = "Price" column.DefaultValue = 25 ' Add the column to the table. table.Columns.Add(column) ' Add 10 rows and set values. Dim row As DataRow Dim i As Integer For i = 0 to 9 row = table.NewRow() row("Price") = i + 1 ' Be sure to add the new row to ' the DataRowCollection. table.Rows.Add(row) Next i End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.