DataRow.RowError 属性

获取或设置行的自定义错误说明。

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

语法

声明
Public Property RowError As String
用法
Dim instance As DataRow
Dim value As String

value = instance.RowError

instance.RowError = value
public string RowError { get; set; }
public:
property String^ RowError {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_RowError ()

/** @property */
public void set_RowError (String value)
public function get RowError () : String

public function set RowError (value : String)

属性值

描述错误的文本。

备注

使用 HasErrors 属性首先确定 DataRow 中是否包含错误。

示例

下面的示例为显示在 DataGrid 控件中的表的十行设置错误文本。

Private Sub SetRowErrors(ByVal table As DataTable)
    ' Set error text for ten rows. 
    Dim i As Integer
    For i = 0 to 10
        ' Insert column 1 value into each error.
        table.Rows(i).RowError = "ERROR: " & _
            table.Rows(i)(1).ToString()
    Next
    ' Get the DataSet for the table, and test it for errors.
    Dim dataSet As DataSet = table.DataSet
    TestForErrors(dataSet)
End Sub
 
Private Sub TestForErrors(ByVal dataSet As DataSet)
    ' Test for errors. If DataSet has errors, 
    ' test each table.
    If dataSet.HasErrors
        Dim tempDataTable As DataTable
        For Each tempDataTable in dataSet.Tables
            ' If the table has errors, then print them.
            If(tempDataTable.HasErrors) Then 
                PrintRowErrs(tempDataTable)
            End If
        Next
        ' Refresh the DataGrid to see the error-marked rows.
        DataGrid1.Refresh()
    End If
End Sub
 
Private Sub PrintRowErrs(ByVal table As DataTable)
    Dim row As DataRow
    For Each row in table.Rows
       If(row.HasErrors) Then
          Console.WriteLine(row.RowError)
       End If
    Next
End Sub
private void SetRowErrors(DataTable table)
{
    // Set error text for ten rows. 
    for(int i = 0; i < 10; i++)
    {
        // Insert column 1 value into each error.
        table.Rows[i].RowError = "ERROR: " 
            + table.Rows[i][1];
    }
    // Get the DataSet for the table, and test it for errors.
    DataSet dataSet = table.DataSet;
    TestForErrors(dataSet);
}
 
private void TestForErrors(DataSet dataSet)
{
    // Test for errors. If DataSet has errors, test each table.
    if(dataSet.HasErrors)
    {
        foreach(DataTable tempDataTable in dataSet.Tables)
        {
            // If the table has errors, then print them.
            if(tempDataTable.HasErrors) 
                PrintRowErrs(tempDataTable);
        }
        // Refresh the DataGrid to see the error-marked rows.
        dataGrid1.Refresh();
    }
}
 
private void PrintRowErrs(DataTable table)
{
    foreach(DataRow row in table.Rows)
    {
        if(row.HasErrors) 
        {
            Console.WriteLine(row.RowError);
        }
    }
}

平台

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 命名空间
SetColumnError
HasErrors