This documentation is archived and is not being maintained.

DataTable.GetErrors Method

Gets an array of DataRow objects that contain errors.

[Visual Basic]
Public Function GetErrors() As DataRow()
[C#]
public DataRow[] GetErrors();
[C++]
public: DataRow* GetErrors() [];
[JScript]
public function GetErrors() : DataRow[];

Return Value

An array of DataRow objects that have errors.

Remarks

Invoke GetErrors after invoking the DataSet class's GetChanges method. Also, be sure you don't invoke the AcceptChanges on the DataTable until after all errors have been succesfully resolved, and the DataSet re-submitted for updating.

Example

[Visual Basic, C#, C++] The following example uses the GetErrors method to return an array of DataRow objects that have errors.

[Visual Basic] 
Private Sub PrintAllErrs(ByVal myDataSet As DataSet)
   Dim rowsInError() As DataRow
   Dim myTable As DataTable  
   Dim i As Integer
   Dim myCol As DataColumn
   For Each myTable In myDataSet.Tables
      ' Test if the table has errors. If not, skip it.
      If myTable.HasErrors Then
         ' Get an array of all rows with errors.
         rowsInError = myTable.GetErrors()
         ' Print the error of each column in each row.
         For i = 0 To rowsInError.GetUpperBound(0)
            For Each myCol In myTable.Columns
               Console.WriteLine(myCol.ColumnName, _
               rowsInError(i).GetColumnError(myCol))
            Next
            ' Clear the row errors
         rowsInError(i).ClearErrors
         Next i
      End If
   Next
End Sub

[C#] 
private void PrintAllErrs(DataSet myDataSet){
   DataRow[] rowsInError; 
     
   foreach(DataTable myTable in myDataSet.Tables){
      // Test if the table has errors. If not, skip it.
      if(myTable.HasErrors){
         // Get an array of all rows with errors.
         rowsInError = myTable.GetErrors();
         // Print the error of each column in each row.
         for(int i = 0; i < rowsInError.Length; i++){
            foreach(DataColumn myCol in myTable.Columns){
               Console.WriteLine(myCol.ColumnName + " " + 
               rowsInError[i].GetColumnError(myCol));
            }
         // Clear the row errors
         rowsInError[i].ClearErrors();
         }
      }
   }
}

[C++] 
private:
 void PrintAllErrs(DataSet* myDataSet){
    DataRow* rowsInError[]; 
      
    System::Collections::IEnumerator* myEnum = myDataSet->Tables->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataTable* myTable = __try_cast<DataTable*>(myEnum->Current);
       // Test if the table has errors. If not, skip it.
       if(myTable->HasErrors){
          // Get an array of all rows with errors.
          rowsInError = myTable->GetErrors();
          // Print the error of each column in each row.
          for(int i = 0; i < rowsInError->Length; i++){
             System::Collections::IEnumerator* myEnum1 = myTable->Columns->GetEnumerator();
             while (myEnum1->MoveNext())
             {
                DataColumn* myCol = __try_cast<DataColumn*>(myEnum1->Current);
                Console::WriteLine(S"{0} {1}", myCol->ColumnName, rowsInError[i]->GetColumnError(myCol));
             }
          // Clear the row errors
          rowsInError[i]->ClearErrors();
          }
       }
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | HasErrors | RowError | SetColumnError

Show: