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

설명

모든 테이블의 모든 행이 제거됩니다. 테이블에 자식 행을 분리할 수 있는 적용된 자식 관계가 있는 경우 예외가 생성됩니다.

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

적용 대상

추가 정보