DataColumn::ColumnName Property
Gets or sets the name of the column in the DataColumnCollection.
Assembly: System.Data (in System.Data.dll)
| Exception | Condition |
|---|---|
| ArgumentException | The property is set to nullptr 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. |
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.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.