DataTable.Clear 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
清除所有数据的 DataTable。
public:
void Clear();
C#
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()
以下示例清除所有数据的表。
C#
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
删除所有表中的所有行。 如果表具有任何强制的子关系,导致子行孤立,则会生成异常。
DataSet如果 绑定到 ,XmlDataDocument则调用 DataSet.Clear 或 DataTable.Clear 引发 NotSupportedException。 若要避免这种情况,请遍历每个表,一次删除一行。 使用 NewRow 创建新行时,必须在调用 Clear之前处理这些行。
产品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |