DataRow.HasErrors プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
行にエラーがあるかどうかを示す値を取得します。
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 します。
and GetColumnsInError
メソッドをGetColumnError使用して、エラーのある列を返します。
このメソッドは ClearErrors 、行のすべてのエラーをクリアします。