閱讀英文

共用方式為


DataRow.ClearErrors 方法

定義

清除資料列的錯誤。 這包括 RowError 和以 SetColumnError(Int32, String) 設定的錯誤。

C#
public void ClearErrors ();

範例

下列範例會使用 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();
    }
}

備註

使用 SetColumnErrorGetColumnError 來設定和傳回個別數據行的錯誤。

RowError設定 屬性以設定套用至整個資料列的錯誤。

若要判斷數據行集合是否有任何錯誤存在,請使用 HasErrors 方法。 因此,您可以使用 GetColumnsInError 方法來擷取所有發生錯誤的數據行。

適用於

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

另請參閱