Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Remove Method

DataColumnCollection.Remove Method

Removes a DataColumn object from the collection.

Overload List

Removes the specified DataColumn object from the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Remove(DataColumn)
[C#] public void Remove(DataColumn);
[C++] public: void Remove(DataColumn*);
[JScript] public function Remove(DataColumn);

Removes the DataColumn object with the specified name from the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Remove(String)
[C#] public void Remove(string);
[C++] public: void Remove(String*);
[JScript] public function Remove(String);

Example

[Visual Basic, C#, C++] 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, C#, C++] Note   This example shows how to use one of the overloaded versions of Remove. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub RemoveColumnByName(colName As String)
    Dim cols As DataColumnCollection
    ' Get the DataColumnCollection 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 Sub

[C#] 
private void RemoveColumnByName(string colName){
    DataColumnCollection cols;
    // Get the DataColumnCollection from a DataTable in a DataSet.
    cols = ds.Tables["Suppliers"].Columns;
    if(cols.Contains(colName))
       if(cols.CanRemove(cols[colName])) 
          cols.Remove(colName);
 }

[C++] 
private:
void RemoveColumnByName(String* colName){
    DataColumnCollection* cols;
    // Get the DataColumnCollection from a DataTable in a DataSet.
    cols = ds->Tables->Item[S"Suppliers"]->Columns;
    if(cols->Contains(colName))
       if(cols->CanRemove(cols->Item[colName])) 
          cols->Remove(colName);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataColumnCollection Class | DataColumnCollection Members | System.Data Namespace

Show:
© 2015 Microsoft