DataTable.Clear Método

Definição

Limpa todos DataTable os dados.

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

Exemplos

O exemplo a seguir limpa a tabela de todos os dados.

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

Comentários

Todas as linhas em todas as tabelas são removidas. Uma exceção será gerada se a tabela tiver alguma relação filho imposta que faça com que as linhas filho fiquem órfãs.

Se estiver DataSet associado a um XmlDataDocument, chamando DataSet.Clear ou DataTable.Clear aumentando o NotSupportedException. Para evitar essa situação, percorra cada tabela, removendo cada linha uma de cada vez. Quando você usa NewRow para criar novas linhas, as linhas devem ser processadas antes de você chamar Clear.

Aplica-se a

Confira também