DataTable.GetErrors 方法

获取包含错误的 DataRow 对象的数组。

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

语法

声明
Public Function GetErrors As DataRow()
用法
Dim instance As DataTable
Dim returnValue As DataRow()

returnValue = instance.GetErrors
public DataRow[] GetErrors ()
public:
array<DataRow^>^ GetErrors ()
public DataRow[] GetErrors ()
public function GetErrors () : DataRow[]

返回值

包含错误的 DataRow 对象的数组。

备注

在调用 DataSet 类的 GetChanges 方法之后调用 GetErrors。同样,请确保不要对 DataTable 调用 AcceptChanges,直到所有错误都已成功解决,并且重新提交 DataSet 以进行更新为止。

示例

下面的示例使用 GetErrors 方法返回包含错误的 DataRow 对象的数组。

Private Sub PrintAllErrs(ByVal dataSet As DataSet)
    Dim rowsInError() As DataRow
    Dim table As DataTable  
    Dim i As Integer
    Dim column As DataColumn
    For Each table In dataSet.Tables
       ' Test if the table has errors. If not, skip it.
       If table.HasErrors Then
          ' Get an array of all rows with errors.
          rowsInError = table.GetErrors()
          ' Print the error of each column in each row.
          For i = 0 To rowsInError.GetUpperBound(0)
             For Each column In table.Columns
                Console.WriteLine(column.ColumnName, _
                rowsInError(i).GetColumnError(column))
             Next
             ' Clear the row errors
          rowsInError(i).ClearErrors
          Next i
       End If
    Next
End Sub
private void PrintAllErrs(DataSet dataSet)
{
    DataRow[] rowsInError; 
  
    foreach(DataTable table in dataSet.Tables)
    {
        // Test if the table has errors. If not, skip it.
        if(table.HasErrors)
        {
            // Get an array of all rows with errors.
            rowsInError = table.GetErrors();
            // Print the error of each column in each row.
            for(int i = 0; i < rowsInError.Length; i++)
            {
                foreach(DataColumn column in table.Columns)
                {
                    Console.WriteLine(column.ColumnName + " " + 
                        rowsInError[i].GetColumnError(column));
                }
                // Clear the row errors
                rowsInError[i].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

请参见

参考

DataTable 类
DataTable 成员
System.Data 命名空间
HasErrors
DataRow.RowError 属性
SetColumnError

其他资源

创建和使用 DataTables