DataTable.HasErrors 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,指出資料表所屬 DataSet 的任何資料表中的任何資料列是否存在錯誤。
public:
property bool HasErrors { bool get(); };
C#
[System.ComponentModel.Browsable(false)]
public bool HasErrors { get; }
C#
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableHasErrorsDescr")]
public bool HasErrors { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HasErrors : bool
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableHasErrorsDescr")>]
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean
true
,表示存在錯誤;否則為 false
。
- 屬性
下列範例會 HasErrors 使用 屬性來檢查資料表是否包含錯誤。
C#
private void CheckForErrors(DataSet dataSet)
{
// Invoke GetChanges on the DataSet to create a reduced set.
DataSet thisDataSet = dataSet.GetChanges();
// Check each table's HasErrors property.
foreach(DataTable table in thisDataSet.Tables)
{
// If HasErrors is true, reconcile errors.
if(table.HasErrors)
{
// Insert code to reconcile errors.
}
}
}
Private Sub CheckForErrors(dataSet As DataSet)
' Invoke GetChanges on the DataSet to create a reduced set.
Dim thisDataSet As DataSet = dataSet.GetChanges()
' Check each table's HasErrors property.
Dim table As DataTable
For Each table In thisDataSet.Tables
' If HasErrors is true, reconcile errors.
If table.HasErrors Then
' Insert code to reconcile errors.
End If
Next table
End Sub
當使用者處理 包含在 中的 DataTable一組數據時,如果變更造成一些驗證失敗,您可以將每個變更標示為錯誤。 您可以使用 屬性以錯誤訊息RowError標記整個 DataRow 。 您也可以使用 SetColumnError 方法,在數據列的每個數據行上設定錯誤。
使用 更新數據源DataSet之前,建議您先在目標 DataSet上叫GetChanges用 方法。 方法會產生 DataSet ,其中只包含對原始所做的變更。 將 傳送 DataSet 至數據來源以進行更新之前,請檢查 HasErrors 每個數據表的 屬性,以查看是否有任何錯誤已附加至數據列中的數據列或數據行。
在協調每個錯誤之後,請清除 錯誤與 ClearErrors 的 DataRow
方法。
產品 | 版本 |
---|---|
.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 |