NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataColumn.ColumnName

Gets or sets the name of the column within the ColumnsCollection.

[Visual Basic]
Public Property ColumnName As String
[C#]
public string ColumnName {get; set;}
[C++]
public: __property String* get_ColumnName();
public: __property void set_ColumnName(String*);
[JScript]
public function get ColumnName() : String;
public function set ColumnName(String);

Property Value

The name of the column.

Exceptions

Exception Type Condition
ArgumentException The property is set to a null reference (in Visual Basic Nothing) or an empty string and the column belongs to a collection.
DuplicateNameException A column with the same name already exists in the collection. The name comparison is not case sensitive.

Remarks

When a DataColumn is created, it has no ColumnName value. When the DataColumn is added to a DataTable object's ColumnsCollection, however, it is given a default name ("Column1", "Column2", etc.).

The Caption value is set to the ColumnName value by default.

Example [Visual Basic]

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.

[Visual Basic]

Private Sub PrintColumnNames(ds As DataSet)
   Dim t As DataTable
   Dim dc As DataColumn 
   ' For each table in the DataSet, print the ColumnName.
   For Each t in ds.Tables
      For Each dc in t.Columns
         Console.WriteLine(dc.ColumnName)
      Next
    Next
End Sub

Private Sub AddColumn(myTable As DataTable)
   Dim dc As DataColumn
   dc = New DataColumn("SupplierID")
   With dc
      .DataType = System.Type.GetType("System.String")
      .Unique = True
      .AutoIncrement = False
      .Caption = "SupplierID"
      .ReadOnly = False
      .Sparse = True
   End With
   ' Add the column to the table's columns collection.
   myTable.Columns.Add(dc)
End Sub

See Also

DataColumn Class | DataColumn Members | System.Data Namespace | Caption