Share via


DataRow.HasErrors 属性

获取一个值,该值指示某行是否包含错误。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public ReadOnly Property HasErrors As Boolean
用法
Dim instance As DataRow
Dim value As Boolean

value = instance.HasErrors
public bool HasErrors { get; }
public:
property bool HasErrors {
    bool get ();
}
/** @property */
public boolean get_HasErrors ()
public function get HasErrors () : boolean

属性值

如果该行包含错误,则为 true;否则,为 false

备注

如果该行中的任何 DataColumn 对象包含错误,或者如果 DataRowRowError 属性是空字符串,HasErrors 就会返回 true。

在验证数据时,您可在行的任何列中设置错误。当这样的列显示在 System.Windows.Forms.DataGrid 控件中时,它会带上一个红色感叹号标记,以便向用户说明该列中包含错误。

使用 SetColumnError 在任何列上设置错误。

使用 GetColumnErrorGetColumnsInError 方法返回包含错误的列。

ClearErrors 方法清除行中的所有错误。

示例

下面的示例使用 HasErrors 来查找错误。如果该行有错误,则 GetColumnsInError 方法返回包含错误的列的数组,这些错误之后可以消除。然后,调用 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
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();
    }
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataRow 类
DataRow 成员
System.Data 命名空间
ClearErrors
DataColumnCollection 类
GetColumnError
GetColumnsInError
SetColumnError