DataRow.HasErrors プロパティ

定義

行にエラーがあるかどうかを示す値を取得します。

public:
 property bool HasErrors { bool get(); };
public bool HasErrors { get; }
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean

プロパティ値

行にエラーがある場合は true。それ以外の場合は false

次の例では、 を HasErrors 使用してエラーを検索します。 行にエラーがある場合、 GetColumnsInError メソッドはエラーを含む列の配列を返し、解決できます。 ClearErrorsその後、 メソッドが呼び出され、すべてのエラーがクリアされます。

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();
    }
}
Private Sub GetAllErrs(ByVal row As DataRow)
    ' Declare an array variable for DataColumn objects.
    Dim colArr() As DataColumn 

    ' If the Row has errors, check use GetColumnsInError.
    Dim i As Integer
    If row.HasErrors Then 
       ' Get the array of columns in error.
       colArr = row.GetColumnsInError()
       For i = 0 to colArr.Length - 1
          ' Insert code to fix errors on each column.
          Console.WriteLine(colArr(i).ColumnName)
       Next i

    ' Clear errors after reconciling.
    row.ClearErrors()
    End If
End Sub

注釈

HasErrors は、 true 行内のオブジェクト DataColumn にエラーが含まれている場合、または の プロパティが RowError 空の文字列でない場合は DataRow を返します。

データを検証するときに、行内の任意の列にエラーを設定できます。 このような列は、コントロールに System.Windows.Forms.DataGrid 表示されるときに、赤い感嘆符でマークされ、列がエラーであることをユーザーに通知します。

任意の列にエラーを設定するには、 を使用 SetColumnError します。

および GetColumnsInError メソッドをGetColumnError使用して、エラーのある列を返します。

メソッドは ClearErrors 、行のすべてのエラーをクリアします。

適用対象

こちらもご覧ください