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 Sub New

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 Sub AddDataColumn(ByVal table As DataTable)
    Dim column As DataColumn = New DataColumn()

    ' Set various properties.
    With column
       .ColumnName = "id"
       .DataType = System.Type.GetType("System.Int32")
       .AutoIncrement = True
       .AutoIncrementSeed = 1
       .AutoIncrementStep = 1
       .ReadOnly = True
     End With

    ' Add to Columns collection.
End Sub

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