Export (0) Print
Expand All

DataSet.Clear Method

Clears the DataSet of any data by removing all rows in all tables.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

'Declaration
Public Sub Clear
'Usage
Dim instance As DataSet

instance.Clear
public void Clear ()
public function Clear ()
Not applicable.

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.

The following example clears the DataSet of all rows in all tables.

Private Sub ClearDataSet(ByVal dataSet As DataSet)
    ' To test, print the number rows in each table.
    Dim table As DataTable
    For Each table In dataSet.Tables
        Console.WriteLine(table.TableName & "Rows.Count = " _
            & table.Rows.Count.ToString())
    Next

    ' Clear all rows of each table.
    dataSet.Clear()

    ' Print the number of rows again.
    For Each table In dataSet.Tables
        Console.WriteLine(table.TableName & "Rows.Count = " _
            & table.Rows.Count.ToString())
    Next 
End Sub

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft