This documentation is archived and is not being maintained.

DataColumn Constructor (String)

.NET Framework 1.1

Inititalizes a new instance of the DataColumn class using the specified column name.

[Visual Basic]
Public Sub New( _
   ByVal columnName As String _
public DataColumn(
   string columnName
public: DataColumn(
   String* columnName
public function DataColumn(
   columnName : String


A string that represents the name of the column to be created. If set to a null reference (Nothing in Visual Basic) or an empty string (""), a default name will be given when added to the columns collection.


By default, the name given to a column becomes the Caption property value.


[Visual Basic, C#, C++] The following example creates a new DataColumn with a specified ColumnName.

[Visual Basic] 

 Private Sub AddDataColumn(ByVal myTable As DataTable)
    Dim myColumn As DataColumn 
    myColumn = New DataColumn("id")
    ' Set various properties.
    With myColumn
       .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("id");
    // Set various properties.
    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(S"id");
    // Set various properties.
    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