DataTable.Clear DataTable.Clear DataTable.Clear DataTable.Clear Method

定義

清除所有資料的 DataTableClears the DataTable of all data.

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

範例

下列範例會清除所有資料的資料表。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

備註

所有資料表中的所有資料列都會被移除。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.

XmlDataDocument DataSet.Clear DataTable.Clear 如果系NotSupportedException結至,則呼叫或會引發。DataSetIf 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. 當您使用NewRow建立新的資料列時,必須先處理這些資料列Clear,然後再呼叫。When you use NewRow to create new rows, the rows must be processed before you call Clear.

適用於

另請參閱