DataTable.Clear 方法

清除所有数据的 DataTable

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public Sub Clear
用法
Dim instance As DataTable

instance.Clear
public void Clear ()
public:
void Clear ()
public void Clear ()
public function Clear ()

备注

所有表中的所有行都被移除。如果表中有任何将使子行孤立的强制子关系,则生成异常。

如果 DataSet 绑定到 XmlDataDocument,则调用 DataSet.ClearDataTable.Clear 将引发 NotSupportedException。为避免这种情况,请遍历每个表,逐个移除每一行。

示例

下面的示例清除所有数据的表。

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
private void ClearTable(DataTable table)
{
    try
    {
        table.Clear();
    }
    catch (DataException e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", 
            e.GetType());
    }

}

平台

Windows 98、Windows 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataTable 类
DataTable 成员
System.Data 命名空间

其他资源

创建和使用 DataTables