Adds the specified DataColumn to the columns collection.
[Visual Basic] Overloads Public Sub Add( _ ByVal column As DataColumn _ ) [C#] public void Add( DataColumn column ); [C++] public: void Add( DataColumn* column ); [JScript] public function Add( column : DataColumn );
Exception Type | Condition |
---|---|
ArgumentNullException | The column parameter is a null reference (in Visual Basic Nothing). |
ArgumentException | The column already belongs to this collection, or to another collection. |
DuplicateNameException | The collection already has a column with the same name (the comparison is not case-sensitive). |
InvalidExpressionException | The column has a compute expression and it can't be bound. |
If the collection is succesfully changed by adding or removing columns, the OnCollectionChanged event occurs.
The following example adds a DataColumn to a ColumnsCollection.
[Visual Basic]
Private Sub AddDataColumn() ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns Dim myCol As DataColumn = New DataColumn With myCol .DataType = System.Type.GetType("System.Currency") .ColumnName = "ItemPrice" .Caption = "Price" .ReadOnly = False .Unique = False .DefaultValue = 0 End With cols.Add(myCol) End Sub
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Add Overload List | ColumnName | Contains | DataType | Expression