This documentation is archived and is not being maintained.

DataTableCollection.Remove Method

Removes a specified DataTable object from the collection.

Overload List

Removes the specified DataTable object from the collection.

Supported by the .NET Compact Framework.

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

Removes the DataTable 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 uses the Contains and CanRemove methods to test whether a named table exists and can be removed. If so, the Remove method is called to remove the table.

[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 RemoveTables()
   ' Set the name of the table to test for and remove.
   Dim strName As String = "Suppliers"
   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   Dim dSet As DataSet = CType(DataGrid1.DataSource, DataSet)
   Dim tablesCol As DataTableCollection = dSet.Tables
   If tablesCol.Contains(strName) _
   And tablesCol.CanRemove(tablesCol(strName)) Then 
      tablesCol.Remove(strName)
   End If
End Sub

[C#] 
private void RemoveTables()
{
   // Set the name of the table to test for and remove.
   string strName = "Suppliers";
   // Presuming a DataGrid is displaying more than one table, get its DataSet.
   DataSet dSet = (DataSet)DataGrid1.DataSource;
   DataTableCollection tablesCol = dSet.Tables;
   if (tablesCol.Contains(strName) && tablesCol.CanRemove(tablesCol[strName])) 
      tablesCol.Remove(strName);
}

[C++] 
private:
 void RemoveTables()
 {
    // Set the name of the table to test for and remove.
    String* strName = S"Suppliers";
    // Presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet* dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
    DataTableCollection* tablesCol = dSet->Tables;
    if (tablesCol->Contains(strName) && tablesCol->CanRemove(tablesCol->Item[strName]))
       tablesCol->Remove(strName);
 }

[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

DataTableCollection Class | DataTableCollection Members | System.Data Namespace

Show: