DataRow.HasErrors 속성

정의

행에 오류가 있는지 여부를 나타내는 값을 가져옵니다.

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

속성 값

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는 행에 있는 개체 DataColumn 에 오류가 있거나 해당 속성 DataRowRowError 빈 문자열이 아닌 경우 를 반환 true 합니다.

데이터의 유효성을 검사할 때 행의 모든 열에 오류를 설정할 수 있습니다. 컨트롤에 System.Windows.Forms.DataGrid 표시되는 이러한 열은 사용자에게 열이 오류임을 알리는 빨간색 느낌표로 표시됩니다.

모든 열에 오류를 설정하는 데 사용합니다 SetColumnError .

GetColumnsInError 메서드를 GetColumnError 사용하여 오류가 있는 열을 반환합니다.

이 메서드는 ClearErrors 행에 대한 모든 오류를 지웁니다.

적용 대상

추가 정보