System.Data Namespace DataTableCollection Class
Removes the table at the given index.
[ VB ]
Public Sub RemoveAt ( _
ByVal index As Integer _
)
[ C# ]
public void RemoveAt (
int index
);
[ C++ ]
public: void RemoveAt (
int index
);
[ JScript ]
public function RemoveAt (
index : int
);
- index
- The index of the table to remove.
Exception Type |
Condition |
ArgumentException |
The collection does not have a table at the specified index. |
Use the RemoveAt method to remove the DataTable object at the specified index in the DataTableCollection.
You can also use the Clear method to remove all members of the collection at once.
The CollectionChanged event occurs when a table is successfully removed from the collection.
The following example uses the CanRemove method to test whether the last table in a DataTableCollection can be removed. If so, the RemoveAt method is called to remove the table.
private void RemoveTables ( DataSet ds ) {
// get the DataTableCollection.
DataTableCollection myTables = ds.Tables;
DataTable tbl = myTables [ myTables.Count -1 ];
if ( myTables.CanRemove ( tbl ) ) myTables.RemoveAt ( myTables.Count -1 );
}
Private Sub RemoveTables ( )
' get the DataTableCollection.
Dim myTables As DataTableCollection = ds.Tables
Dim tbl As DataTable = myTables ( myTables.Count -1 );
If myTables.CanRemove ( tbl ) Then myTables.RemoveAt ( myTables.Count -1 );
End Sub |
|
C# |
VB |
DataTableCollection Members Clear Add