asp.net.ph

DataColumn.ColumnName Property

System.Data Namespace   DataColumn Class


Sets or retrieves the name of the column in the DataColumnCollection.

Syntax


Script DataColumn.ColumnName [ = strName ]

Property Value


strName The name of the column.

The property is read/write with no default value.

Exceptions


Exception Type Condition
ArgumentException Occurs when the property is set to a null reference or an empty string and the column belongs to a collection.
DuplicateNameException Occurs when 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 DataColumnCollection, however, it is given a default name ( "Column1", "Column2", etc. ).

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

Example

The following example gets the ColumnName for every column in every table in a DataSet.

private void PrintColumnNames ( DataSet myDataSet ) {


   // for each table in the DataSet, print the ColumnName.
   foreach ( DataTable myTable in myDataSet.Tables ) {
      foreach ( DataColumn myColumn in myTable.Columns ) {
         Response.Write ( myColumn.ColumnName );
      }
    }
}

private void AddColumn ( DataTable myTable ) {
   DataColumn myColumn = new DataColumn ( );

   myColumn.ColumnName = "SupplierID";
   myColumn.DataType = System.Type.GetType ( "System.String" );
   myColumn.Unique = true;
   myColumn.AutoIncrement = false;
   myColumn.Caption = "SupplierID";
   myColumn.ReadOnly = false;

   // add the column to the table's columns collection.
   myTable.Columns.Add ( myColumn );
}
  C# VB

See Also

DataColumn Members   Caption Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph