Removes the column with the specified name from the collection.
[Visual Basic] Overloads Public Sub Remove( _ ByVal name As String _ ) [C#] public void Remove( string name ); [C++] public: void Remove( String* name ); [JScript] public function Remove( name : String );
Exception Type | Condition |
---|---|
IndexOutOfRangeException | The collection doesn't have a column with the specified name. |
If the collection is succesfully changed by adding or removing columns, the OnCollectionChanged event occurs.
The following example first uses the Contains method to determine if a particular column is found in the collection. If it is found, the CanRemove method tests whether the column can be removed. If so, the column is removed with the Remove method.
[Visual Basic]
Private Sub RemoveColumnByName(colName As String) Dim cols As ColumnsCollection ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns If cols.Contains(colName) Then If cols.CanRemove(cols(colName)) Then cols.Remove(colName) End If End If
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Remove Overload List | Contains