DataTable.Clear Method

Definition

Borra el DataTable de todos los datos.Clears the DataTable of all data.

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

Examples

En el siguiente ejemplo se borra la tabla de todos los datos.The following example clears the table of all data.

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

Remarks

Se quitan todas las filas de todas las tablas.All rows in all tables are removed. Se genera una excepción si la tabla tiene relaciones secundarias aplicadas que harían que las filas secundarias estuvieran huérfanas.An exception is generated if the table has any enforced child relations that would cause child rows to be orphaned.

Si el DataSet se enlaza a un XmlDataDocument, al llamar a DataSet.Clear o DataTable.Clear se produce la NotSupportedException.If the DataSet is bound to an XmlDataDocument, calling DataSet.Clear or DataTable.Clear raises the NotSupportedException. Para evitar esta situación, recorra cada tabla y quite cada fila de una en una.To avoid this situation, traverse each table, removing each row one at a time. Al utilizar NewRow para crear nuevas filas, las filas se deben procesar antes de llamar a Clear.When you use NewRow to create new rows, the rows must be processed before you call Clear.

Applies to

See also