DataSet.HasErrors 屬性

定義

取得值,指出這個 DataTable 內的 DataSet 物件中是否有任何一個有錯誤。

public:
 property bool HasErrors { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool HasErrors { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataSetHasErrorsDescr")]
public bool HasErrors { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HasErrors : bool
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataSetHasErrorsDescr")>]
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean

屬性值

Boolean

true 如果有任何資料表包含錯誤,則為 ;否則為 false

屬性

範例

下列範例會 HasErrors 使用 屬性來判斷物件是否 DataSet 包含錯誤。 如果是,則會列印每 DataRow DataTable 一個的錯誤。

private void CheckForErrors()
{
    if(!DataSet1.HasErrors)
    {
        DataSet1.Merge(DataSet2);
    }
    else
    {
        PrintRowErrs(DataSet1);
    }
}

private void PrintRowErrs(DataSet dataSet)
{
    foreach(DataTable table in dataSet.Tables)
    {
        foreach(DataRow row in table.Rows)
        {
            if(row.HasErrors)
            {
                Console.WriteLine(row.RowError);
            }
        }
    }
}
Private Sub CheckForErrors()
    If Not DataSet1.HasErrors Then
        DataSet1.Merge(DataSet2)
    Else
       PrintRowErrs(DataSet1)
    End If
End Sub
 
Private Sub PrintRowErrs(ByVal dataSet As DataSet)
    Dim row As DataRow
    Dim table As DataTable
    For Each table In  dataSet.Tables
       For Each row In table.Rows
          If row.HasErrors Then
             Console.WriteLine(row.RowError)
          End If
       Next
    Next
End Sub

備註

中的每個 DataTable DataSet 也都有 HasErrors 屬性。 HasErrors使用第一個 的 DataSet 屬性,在檢查個別 DataTable 物件之前,先判斷是否有任何資料表發生錯誤。 DataTable如果 發生錯誤,方法 GetErrors 會傳回包含錯誤的 物件陣列 DataRow

適用於

另請參閱