This documentation is archived and is not being maintained.

DataSet.HasErrors Property

Gets a value indicating whether there are errors in any of the DataTable objects within this DataSet.

[Visual Basic]
Public ReadOnly Property HasErrors As Boolean
[C#]
public bool HasErrors {get;}
[C++]
public: __property bool get_HasErrors();
[JScript]
public function get HasErrors() : Boolean;

Property Value

true if any table contains an error;otherwise, false.

Remarks

Each DataTable in a DataSet also has a HasErrors property. Use the HasErrors property of the DataSet first, to determine if any table has errors, before checking individual DataTable objects. If a DataTable has errors, the GetErrors method returns an array of DataRow objects containing the errors.

Example

[Visual Basic, C#, C++] The following example uses the HasErrors property to determine whether a DataSet object contains errors. If so, the errors for each DataRow in each DataTable are printed.

[Visual Basic] 
Private Sub CheckForErrors()
   If Not DataSet1.HasErrors Then
       DataSet1.Merge(DataSet2)
   Else
      PrintRowErrs(DataSet1)
   End If
End Sub

Private Sub PrintRowErrs(ByVal myDataSet As DataSet)
   Dim myRow As DataRow
   Dim myTable As DataTable
   For Each myTable In  myDataSet.Tables
      For Each myRow In myTable.Rows
         If myRow.HasErrors Then
            Console.WriteLine(myRow.RowError)
         End If
      Next
   Next
End Sub

[C#] 
private void CheckForErrors(){
   if(!DataSet1.HasErrors){
       DataSet1.Merge(DataSet2);
   }
   else{
      PrintRowErrs(DataSet1);
   }
}

private void PrintRowErrs(DataSet myDataSet){
   foreach(DataTable myTable in myDataSet.Tables){
      foreach(DataRow myRow in myTable.Rows){
         if(myRow.HasErrors){
            Console.WriteLine(myRow.RowError);
         }
      }
   }
}

[C++] 
private:
 void CheckForErrors(){
    if(!DataSet1->HasErrors){
        DataSet1->Merge(DataSet2);
    }
    else{
       PrintRowErrs(DataSet1);
    }
 }
 
 void PrintRowErrs(DataSet* myDataSet){
    System::Collections::IEnumerator* myEnum = myDataSet->Tables->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataTable* myTable = __try_cast<DataTable*>(myEnum->Current);
       System::Collections::IEnumerator* myEnum1 = myTable->Rows->GetEnumerator();
       while (myEnum1->MoveNext())
       {
          DataRow* myRow = __try_cast<DataRow*>(myEnum1->Current);
          if(myRow->HasErrors){
             Console::WriteLine(myRow->RowError);
          }
       }
    }
 }

[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

DataSet Class | DataSet Members | System.Data Namespace | GetChanges

Show: