閱讀英文

共用方式為


DataRow.HasErrors 屬性

定義

取得值,指出資料列中是否有錯誤。

C#
public bool HasErrors { get; }

屬性值

如果資料列含有錯誤,則為 true,否則為 false

範例

下列範例會使用 HasErrors 來尋找錯誤。 如果數據列有錯誤,此方法會 GetColumnsInError 傳回數據行陣列,並接著可以解決這些錯誤。 接著會 ClearErrors 呼叫 方法,以清除所有錯誤。

C#
private void GetAllErrs(DataRow row)
{
    // Declare an array variable for DataColumn objects.
    DataColumn[] colArr;
    // If the Row has errors, check use GetColumnsInError.
    if(row.HasErrors)
    {
        // Get the array of columns in error.
        colArr = row.GetColumnsInError();
        for(int i = 0; i < colArr.Length; i++)
        {
            // Insert code to fix errors on each column.
            Console.WriteLine(colArr[i].ColumnName);
        }
        // Clear errors after reconciling.
        row.ClearErrors();
    }
}

備註

HasErrors true如果資料欄取任何DataColumn物件包含錯誤,或 RowErrorDataRow 屬性不是空字串,則會傳回 。

驗證資料時,您可以在資料列中的任何資料行上設定錯誤。 在控件中 System.Windows.Forms.DataGrid 顯示這類數據行時,會以紅色驚嘆號標示,以向使用者發出錯誤數據行的訊號。

使用 SetColumnError 在任何數據行上設定錯誤。

GetColumnError使用和 GetColumnsInError 方法可傳回發生錯誤的數據行。

方法 ClearErrors 會清除資料列的所有錯誤。

適用於

產品 版本
.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

另請參閱