DataTableCollection.Remove 메서드

정의

컬렉션에서 지정된 DataTable 개체를 제거합니다.

오버로드

Remove(String, String)

컬렉션에서 지정된 이름의 DataTable 개체를 제거합니다.

Remove(DataTable)

컬렉션에서 지정된 DataTable 개체를 제거합니다.

Remove(String)

컬렉션에서 지정된 이름의 DataTable 개체를 제거합니다.

Remove(String, String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
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 네임스페이스의 이름입니다.

예외

컬렉션에 이름이 지정된 테이블이 없는 경우

예제

다음 예제에서는 및 CanRemove 메서드를 Contains 사용하여 명명된 테이블이 있는지 여부를 테스트하고 제거할 수 있습니다. 이 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하기 전에 지정된 테이블이 존재하고 제거할 수 있는지 확인하려면 및 메서드를 ContainsCanRemove 사용합니다.

추가 정보

적용 대상

Remove(DataTable)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
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하기 전에 지정된 테이블이 존재하고 제거할 수 있는지 확인하려면 및 메서드를 ContainsCanRemove 사용합니다.

추가 정보

적용 대상

Remove(String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
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 개체의 이름입니다.

예외

컬렉션에 이름이 지정된 테이블이 없는 경우

예제

다음 예제에서는 및 CanRemove 메서드를 Contains 사용하여 명명된 테이블이 있는지 여부를 테스트하고 제거할 수 있습니다. 이 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하기 전에 지정된 테이블이 존재하고 제거할 수 있는지 확인하려면 및 메서드를 ContainsCanRemove 사용합니다.

추가 정보

적용 대상