指定した名前の DataTable オブジェクトをコレクションから削除します。
Overloads Public Sub Remove( _
ByVal name As String _)
[C#]
public void Remove(stringname);
[C++]
public: void Remove(String* name);
[JScript]
public function Remove(
name : String);
パラメータ
- name
削除する DataTable オブジェクトの名前。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | このコレクションには指定した名前のテーブルがありません。 |
解説
テーブルが正常に削除されると、 OnCollectionChanged イベントが発生します。
Remove を呼び出す前にそのテーブルが存在するかどうか、および削除できるかどうかを確認するには、 Contains メソッドと CanRemove メソッドを使用します。
使用例
[Visual Basic, C#, C++] Contains メソッドと CanRemove メソッドを使用して、指定したテーブルが存在するかどうか、および削除できるかどうかを確認する例を次に示します。削除できる場合は、テーブルを削除するために Remove メソッドが呼び出されます。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | DataTableCollection.Remove オーバーロードの一覧 | IndexOf | Contains