DataTable.Clear 메서드

정의

DataTable의 모든 데이터를 지웁니다.

public:
 void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()

예제

다음 예제에서는 모든 데이터의 테이블을 지웁니다.

private void ClearTable(DataTable table)
{
    try
    {
        table.Clear();
    }
    catch (DataException e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Private Sub ClearTable(table As DataTable)
    Try
        table.Clear()
    Catch e As DataException
    ' Process exception and return.
         Console.WriteLine("Exception of type {0} occurred.", _
           e.GetType().ToString())
    End Try
End Sub

설명

모든 테이블의 모든 행이 제거됩니다. 테이블에 자식 행이 분리되는 강제 자식 관계가 있는 경우 예외가 생성됩니다.

가 에 DataSet 바인딩된 경우 를 XmlDataDocument호출 DataSet.Clear 하거나 DataTable.Clear 을 발생합니다 NotSupportedException. 이러한 상황을 방지하려면 각 테이블을 트래버스하여 각 행을 한 번에 하나씩 제거합니다. 를 사용하여 NewRow 새 행을 만드는 경우 를 호출 Clear하기 전에 행을 처리해야 합니다.

적용 대상

추가 정보