Export (0) Print
Expand All

DataColumn.ColumnName Property

Gets or sets the name of the column in the DataColumnCollection.

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

Public Property ColumnName As String

Property Value

Type: System.String
The name of the column.


The property is set to Nothing or an empty string and the column belongs to a collection.


A column with the same name already exists in the collection. The name comparison is not case sensitive.

When a DataColumn is created, it has no ColumnName value. However, when the DataColumn is added to a DataColumnCollection for a DataTable object, it is given a default name ("Column1", "Column2", and so on).

By default, the Caption value is set to the ColumnName value.

The following examples gets the ColumnName for every column in every table in a DataSet. The example also shows how to create a DataColumn with a new ColumnName.

Private Sub PrintColumnNames(dataSet As DataSet)
    Dim table As DataTable
    Dim column As DataColumn 

    ' For each DataTable, print the ColumnName.
    For Each table in dataSet.Tables
        For Each column in table.Columns
End Sub

Private Sub AddColumn(table As DataTable)
    Dim column As DataColumn
    column = New DataColumn()

    With column
        .ColumnName = "SupplierID"
        .DataType = System.Type.GetType("System.String")
        .Unique = True
        .AutoIncrement = False
        .Caption = "SupplierID"
        .ReadOnly = False
    End With

    ' Add the column to the table's columns collection.
End Sub

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft