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 |