DataRowCollection.Remove(DataRow) 메서드

정의

지정된 DataRow를 컬렉션에서 제거합니다.

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

매개 변수

row
DataRow

제거할 DataRow입니다.

예제

다음 예제에서는 메서드를 Remove 사용하여 개체에서 찾은 행을 DataRowCollection 삭제합니다. 이 예제에서는 먼저 메서드를 Contains 사용하여 행 컬렉션에 행이 포함되어 있는지 여부를 확인합니다. 이 경우 메서드는 Find 특정 행을 찾는 데 사용되고 메서드 Remove 는 행을 제거하는 데 사용됩니다.

Private Sub RemoveFoundRow(ByVal table As DataTable)
    Dim rowCollection As DataRowCollection = table.Rows

    ' Test to see if the collection contains the value.
    If rowCollection.Contains(TextBox1.Text) Then
        Dim foundRow As DataRow = rowCollection.Find(TextBox1.Text)
        rowCollection.Remove(foundRow)
        Console.WriteLine("Row Deleted")
    Else
        Console.WriteLine("No such row found.")
    End If
 End Sub

설명

행이 제거되면 해당 행의 모든 데이터가 손실됩니다. 클래스의 DataRow 메서드를 Delete 호출하여 제거를 위해 행을 표시할 수도 있습니다. 호출 Remove 은 를 호출한 다음 를 호출 DeleteAcceptChanges하는 것과 같습니다.

Remove 개체를 반복하는 DataRowCollection 동안 foreach 루프에서 를 호출해서는 안 됩니다. Remove 컬렉션의 상태를 수정합니다.

메서드를 Clear 사용하여 컬렉션의 모든 멤버를 한 번에 제거할 수도 있습니다.

적용 대상

추가 정보