This documentation is archived and is not being maintained.

DataColumnCollection.Add Method (DataColumn)

.NET Framework 1.1

Creates and adds the specified DataColumn object to the DataColumnCollection.

[Visual Basic]
Overloads Public Sub Add( _
   ByVal column As DataColumn _
public void Add(
 DataColumn column
public: void Add(
 DataColumn* column
public function Add(
   column : DataColumn


The DataColumn to add.


Exception Type Condition
ArgumentNullException The column parameter is a null reference (Nothing in Visual Basic).
ArgumentException The column already belongs to this collection, or to another collection.
DuplicateNameException The collection already has a column with the specified name. (The comparison is not case-sensitive.)
InvalidExpressionException The expression is invalid. See the Expression property for details on creating expressions.


If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.


[Visual Basic] The following example adds a DataColumn to a DataColumnCollection.

[Visual Basic] 
Private Sub AddDataColumn()
    ' Get the DataColumnCollection from a DataTable in a DataSet.
    Dim cols As DataColumnCollection = DataSet1.Tables("Orders").Columns
    Dim myCol As DataColumn = New DataColumn
    With myCol
       .DataType = System.Type.GetType("System.Decimal")
       .ColumnName = "ItemPrice"
       .Caption = "Price"
       .ReadOnly = False
       .Unique = False
       .DefaultValue = 0
    End With
 End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic 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

DataColumnCollection Class | DataColumnCollection Members | System.Data Namespace | DataColumnCollection.Add Overload List | ColumnName | CollectionChanged | Contains | DataType | Expression