Ler em inglês

Compartilhar via


DataSet.Clear Método

Definição

Limpa o DataSet de todos os dados, removendo todas as linhas em todas as tabelas.

public void Clear ();

Exemplos

O exemplo a seguir limpa o DataSet de todas as linhas em todas as tabelas.

private void ClearDataSet(DataSet dataSet)
{
    // To test, print the number rows in each table.
    foreach(DataTable table in dataSet.Tables)
    {
        Console.WriteLine(table.TableName + "Rows.Count = "
            + table.Rows.Count.ToString());
    }
    // Clear all rows of each table.
    dataSet.Clear();

    // Print the number of rows again.
    foreach(DataTable table in dataSet.Tables)
    {
        Console.WriteLine(table.TableName + "Rows.Count = "
            + table.Rows.Count.ToString());
    }
}

Comentários

Se o DataSet estiver associado a um XmlDataDocument, chamar DataSet.Clear ou DataTable.Clear gerará o NotSupportedException. Para evitar essa situação, percorra cada tabela, removendo cada linha uma de cada vez.

Aplica-se a

Produto Versões
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Confira também