This documentation is archived and is not being maintained.

DataTableCollection.Clear Method

Clears the collection of all DataTable objects.

[Visual Basic]
Public Sub Clear()
public void Clear();
public: void Clear();
public function Clear();


To remove a particular DataTable from the collection, use the Remove method.


[Visual Basic, C#, C++] The following example gets the DataTableCollection of a DataSet, then clears the collection of all tables.

[Visual Basic] 
Private Sub ClearTables()
  Dim myDataSet As DataSet
  Dim tablesCol As DataTableCollection
  ' Get the DataSet of a DataGrid control.
  myDataSet = CType(DataGrid1.DataSource, DataSet)
  tablesCol = myDataSet.Tables
  ' Clear the collection.
End Sub

private void ClearTables()
  DataSet myDataSet;
  DataTableCollection tablesCol;
  // Get the DataSet of a DataGrid control.
  myDataSet = (DataSet)DataGrid1.DataSource;
  tablesCol = myDataSet.Tables;
  // Clear the collection.

 void ClearTables()
   DataSet* myDataSet;
   DataTableCollection* tablesCol;
   // Get the DataSet of a DataGrid control.
   myDataSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
   tablesCol = myDataSet->Tables;
   // Clear the collection.

[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.


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

DataTableCollection Class | DataTableCollection Members | System.Data Namespace