DataTable.Clear Metode

Definisi

DataTable Menghapus semua data.

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

Contoh

Contoh berikut menghapus tabel semua 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

Keterangan

Semua baris di semua tabel dihapus. Pengecualian dihasilkan jika tabel memiliki hubungan anak yang diberlakukan yang akan menyebabkan baris anak menjadi yatim piatu.

DataSet Jika terikat ke XmlDataDocument, memanggil DataSet.Clear atau DataTable.Clear menaikkan NotSupportedException. Untuk menghindari situasi ini, melintasi setiap tabel, menghapus setiap baris satu per satu. Saat Anda menggunakan NewRow untuk membuat baris baru, baris harus diproses sebelum Anda memanggil Clear.

Berlaku untuk

Lihat juga