DataTableCollection.Remove メソッド

定義

指定された DataTable オブジェクトをコレクションから削除します。

オーバーロード

Remove(String, String)

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

Remove(DataTable)

指定した DataTable オブジェクトをコレクションから削除します。

Remove(String)

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

Remove(String, String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

public:
 void Remove(System::String ^ name, System::String ^ tableNamespace);
public void Remove (string name, string tableNamespace);
member this.Remove : string * string -> unit
Public Sub Remove (name As String, tableNamespace As String)

パラメーター

name
String

削除する DataTable オブジェクトの名前。

tableNamespace
String

検索する DataTable 名前空間の名前。

例外

このコレクションには指定した名前のテーブルがありません。

次の例では、 Contains メソッドと CanRemove メソッドを使用して、名前付きテーブルが存在し、削除できるかどうかをテストします。 その場合は、 メソッドが Remove 呼び出されてテーブルが削除されます。

private void RemoveTables()
{
    // Set the name of the table to test for and remove.
    string name = "Suppliers";

    // Presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
    DataTableCollection tablesCol = thisDataSet.Tables;
    if (tablesCol.Contains(name) && tablesCol.CanRemove(tablesCol[name]))
        tablesCol.Remove(name);
}
Private Sub RemoveTables()
   ' Set the name of the table to test for and remove.
   Dim name As String = "Suppliers"

   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)
   Dim tablesCol As DataTableCollection = thisDataSet.Tables
   If tablesCol.Contains(name) _
   And tablesCol.CanRemove(tablesCol(name)) Then 
      tablesCol.Remove(name)
   End If
End Sub

注釈

イベントは CollectionChanged 、テーブルが正常に削除されたときに発生します。

を呼び出すRemove前に特定のテーブルが存在し、削除できるかどうかを判断するには、 メソッドと メソッドをCanRemove使用Containsします。

こちらもご覧ください

適用対象

Remove(DataTable)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs

指定した DataTable オブジェクトをコレクションから削除します。

public:
 void Remove(System::Data::DataTable ^ table);
public void Remove (System.Data.DataTable table);
member this.Remove : System.Data.DataTable -> unit
Public Sub Remove (table As DataTable)

パラメーター

table
DataTable

削除する DataTable

例外

このテーブルに指定した値が null です。

このテーブルはこのコレクションに属していません。

- または -

このテーブルはリレーションシップの一部です。

次の例では、 メソッドを CanRemove 使用して、各テーブルを から DataSet削除できるかどうかをテストします。 その場合は、 メソッドが Remove 呼び出されてテーブルが削除されます。

public static void DataTableCollectionCanRemove()
{
    // create a DataSet with two tables
    DataSet dataSet = new DataSet();

    // create Customer table
    DataTable customersTable = new DataTable("Customers");
    customersTable.Columns.Add("customerId",
        typeof(int) ).AutoIncrement = true;
    customersTable.Columns.Add("name",
        typeof(string));
    customersTable.PrimaryKey = new DataColumn[]
        { customersTable.Columns["customerId"] };

    // create Orders table
    DataTable ordersTable = new DataTable("Orders");
    ordersTable.Columns.Add("orderId",
        typeof(int) ).AutoIncrement = true;
    ordersTable.Columns.Add("customerId",
        typeof(int) );
    ordersTable.Columns.Add("amount",
        typeof(double));
    ordersTable.PrimaryKey = new DataColumn[]
        { ordersTable.Columns["orderId"] };

    dataSet.Tables.AddRange(new DataTable[]
        {customersTable, ordersTable });

    // remove all tables
    // check if table can be removed and then
    // remove it, cannot use a foreach when
    // removing items from a collection
    while(dataSet.Tables.Count > 0)
    {
        DataTable table = dataSet.Tables[0];
        if(dataSet.Tables.CanRemove(table))
        {
            dataSet.Tables.Remove(table);
        }
    }

    Console.WriteLine("dataSet has {0} tables",
        dataSet.Tables.Count);
}
Public Sub Main
DataTableCollectionCanRemove
End Sub

Public Sub DataTableCollectionCanRemove()
    ' create a DataSet with two tables
    Dim dataSet As New DataSet()

    ' create Customer table
    Dim customersTable As New DataTable("Customers")
    customersTable.Columns.Add("customerId", _
        System.Type.GetType("System.Integer")).AutoIncrement = True
    customersTable.Columns.Add("name", _
        System.Type.GetType("System.String"))
    customersTable.PrimaryKey = New DataColumn() _
        {customersTable.Columns("customerId")}

    ' create Orders table
    Dim ordersTable As New DataTable("Orders")
    ordersTable.Columns.Add("orderId", _
        System.Type.GetType("System.Integer")).AutoIncrement = True
    ordersTable.Columns.Add("customerId", _
        System.Type.GetType("System.Integer"))
    ordersTable.Columns.Add("amount", _
        System.Type.GetType("System.Double"))
    ordersTable.PrimaryKey = New DataColumn() _
        {ordersTable.Columns("orderId")}

    dataSet.Tables.AddRange(New DataTable() {customersTable, ordersTable})

    ' remove all tables
    ' check if table can be removed and then
    ' remove it, cannot use a foreach when
    ' removing items from a collection
    Do While (dataSet.Tables.Count > 0)
        Dim table As DataTable = dataSet.Tables(0)
        If (dataSet.Tables.CanRemove(table)) Then
            dataSet.Tables.Remove(table)
        End If
    Loop

Console.WriteLine("dataSet has {0} tables", dataSet.Tables.Count)
End Sub

注釈

イベントは CollectionChanged 、テーブルが正常に削除されたときに発生します。

を呼び出すRemove前に特定のテーブルが存在し、削除できるかどうかを判断するには、 メソッドと メソッドをCanRemove使用Containsします。

こちらもご覧ください

適用対象

Remove(String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

public:
 void Remove(System::String ^ name);
public void Remove (string name);
member this.Remove : string -> unit
Public Sub Remove (name As String)

パラメーター

name
String

削除する DataTable オブジェクトの名前。

例外

このコレクションには指定した名前のテーブルがありません。

次の例では、 Contains メソッドと CanRemove メソッドを使用して、名前付きテーブルが存在し、削除できるかどうかをテストします。 その場合は、 メソッドが Remove 呼び出されてテーブルが削除されます。

private void RemoveTables()
{
    // Set the name of the table to test for and remove.
    string name = "Suppliers";

    // Presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
    DataTableCollection tablesCol = thisDataSet.Tables;
    if (tablesCol.Contains(name) && tablesCol.CanRemove(tablesCol[name]))
        tablesCol.Remove(name);
}
Private Sub RemoveTables()
   ' Set the name of the table to test for and remove.
   Dim name As String = "Suppliers"

   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)
   Dim tablesCol As DataTableCollection = thisDataSet.Tables
   If tablesCol.Contains(name) _
   And tablesCol.CanRemove(tablesCol(name)) Then 
      tablesCol.Remove(name)
   End If
End Sub

注釈

イベントは CollectionChanged 、テーブルが正常に削除されたときに発生します。

を呼び出すRemove前に特定のテーブルが存在し、削除できるかどうかを判断するには、 メソッドと メソッドをCanRemove使用Containsします。

こちらもご覧ください

適用対象