This documentation is archived and is not being maintained.

DataColumn Constructor ()

.NET Framework 1.1

Initializes a new instance of a DataColumn class.

[Visual Basic]
Public Sub New()
public DataColumn();
public: DataColumn();
public function DataColumn();


When created, a new DataColumn object has no default ColumnName or Caption property. When added to a DataColumnCollection, however, a default name ("Column1", "Column2", and so on) is given to the column.


[Visual Basic, C#, C++] The following example creates a new DataColumn, sets various properties, and adds it to a DataTable object's DataColumnCollection.

[Visual Basic] 
Private Sub AddDataColumn(ByVal myTable As DataTable)
    Dim myColumn As DataColumn 
    myColumn = New DataColumn()
    ' Set various properties.
    With myColumn
       .ColumnName = "id"
       .DataType = System.Type.GetType("System.Int32")
       .AutoIncrement = True
       .AutoIncrementSeed = 1
       .AutoIncrementStep = 1
       .ReadOnly = True
     End With
    ' Add to Columns collection.
 End Sub

private void AddDataColumn(DataTable myTable){
    DataColumn myColumn = new DataColumn();
    // Set various properties.
    myColumn.ColumnName = "id";
    myColumn.DataType = System.Type.GetType("System.Int32");
    myColumn.AutoIncrement = true;
    myColumn.AutoIncrementSeed = 1;
    myColumn.AutoIncrementStep = 1;
    myColumn.ReadOnly = true;
    // Add to Columns collection.

void AddDataColumn(DataTable* myTable){
    DataColumn* myColumn = new DataColumn();
    // Set various properties.
    myColumn->ColumnName = S"id";
    myColumn->DataType = System::Type::GetType(S"System.Int32");
    myColumn->AutoIncrement = true;
    myColumn->AutoIncrementSeed = 1;
    myColumn->AutoIncrementStep = 1;
    myColumn->ReadOnly = true;
    // Add to Columns collection.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | DataColumn Constructor Overload List | ColumnName | Caption | DefaultValue | DataTable | DataType