DataColumn Constructor

DataColumn Constructor ()


Initializes a new instance of a DataColumn class as type string.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

public DataColumn()

When created, a DataColumn object has no default ColumnName or Caption. When you add it to a DataColumnCollection, a default name ("Column1", "Column2", and so on) will be generated if a name has not been assigned to the ColumnName.

The following example creates a new DataColumn, sets various properties, and adds it to a DataColumnCollection for the DataTable object.

private void AddDataColumn(DataTable table)
    DataColumn column = new DataColumn();

    // Set various properties.
    column.ColumnName = "id";
    column.DataType = System.Type.GetType("System.Int32");
    column.AutoIncrement = true;
    column.AutoIncrementSeed = 1;
    column.AutoIncrementStep = 1;
    column.ReadOnly = true;

    // Add to Columns collection.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft