Export (0) Print
Expand All

DataTableCollection.CanRemove Method

Verifies if the specified DataTable object can be removed from the collection.

[Visual Basic]
Public Function CanRemove( _
   ByVal table As DataTable _
) As Boolean
[C#]
public bool CanRemove(
 DataTable table
);
[C++]
public: bool CanRemove(
 DataTable* table
);
[JScript]
public function CanRemove(
   table : DataTable
) : Boolean;

Parameters

table
The DataTable in the collection to perform the check against.

Return Value

true if the table can be removed; otherwise, false.

Example

[Visual Basic, C#, C++] The following example uses the CanRemove to test whether each table can be removed from a DataSet. If so, the Remove method is called to remove the table.

[Visual Basic] 
Private Sub RemoveTables()
   Dim t As DataTable
   Dim dSet As DataSet
   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   dSet = CType(DataGrid1.DataSource, DataSet)
   Do While dSet.Tables.Count > 0
      t = dSet.Tables(0)
      If dSet.Tables.CanRemove(t) Then
         dSet.Tables.Remove(t)
      End If
   Loop
End Sub

[C#] 
private void RemoveTables()
{
   DataTable t;
   DataSet dSet;
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   dSet = (DataSet)DataGrid1.DataSource;
   while (dSet.Tables.Count > 0)
   {
      t = dSet.Tables[0];
      if (dSet.Tables.CanRemove(t))
         dSet.Tables.Remove(t);
   }
}

[C++] 
private:
 void RemoveTables()
 {
    DataTable* t;
    DataSet* dSet;
    // presuming a DataGrid is displaying more than one table, get its DataSet.
    dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
    while (dSet->Tables->Count > 0)
    {
       t = dSet->Tables->Item[0];
       if (dSet->Tables->CanRemove(t))
          dSet->Tables->Remove(t);
    }
 }

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

Requirements

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 | Item | IndexOf | Remove

Show:
© 2014 Microsoft