DataTable.HasErrors 屬性

定義

取得值,指出資料表所屬 DataSet 的任何資料表中的任何資料列是否存在錯誤。

public:
 property bool HasErrors { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool HasErrors { get; }
[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 使用 屬性來檢查資料表是否包含錯誤。

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 每個數據表的 屬性,以查看是否有任何錯誤已附加至數據列中的數據列或數據行。

在協調每個錯誤之後,請清除 錯誤與 ClearErrorsDataRow方法。

適用於

另請參閱