Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


DataTable.Clear Method

Definition

Clears the DataTable of all data.

C#
public void Clear();

Examples

The following example clears the table of all data.

C#
private void ClearTable(DataTable table)
{
    try
    {
        table.Clear();
    }
    catch (DataException e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}

Remarks

All rows in all tables are removed. An exception is generated if the table has any enforced child relations that would cause child rows to be orphaned.

If the DataSet is bound to an XmlDataDocument, calling DataSet.Clear or DataTable.Clear raises the NotSupportedException. To avoid this situation, traverse each table, removing each row one at a time. When you use NewRow to create new rows, the rows must be processed before you call Clear.

Applies to

Termék Verziók
.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

See also