This documentation is archived and is not being maintained.

DataTable.HasErrors Property

Gets a value indicating whether there are errors in any of the rows in any of the tables of the DataSet to which the table belongs.

[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 errors exist, otherwise, false.

Remarks

As users work on a set of data contained in a DataSet, you can mark each change with an error if the change causes some validation failure. You can mark an entire DataRow with an error message using the RowError property. You can also set errors on each column of the row with the SetColumnError method.

Before updating a data source with a DataSet, it's recommended that you first invoke the GetChanges method on the target DataSet. The method results in a DataSet that contains only the changes made to the original. Before sending the DataSet to the data source for updating, check the HasErrors property of each table to see if any errors have been attached to the rows or columns in the rows.

After reconciling each error, clear the errors with the ClearErrors method of the DataRow.

Example

[Visual Basic, C#, C++] The following example uses the HasErrors property to check if a table contains errors.

[Visual Basic] 
Private Sub CheckForErrors(myDataSet As DataSet)
    ' Invoke GetChanges on the DataSet to create a reduced set.
    Dim xDataSet As DataSet = myDataSet.GetChanges()
    ' Check each table's HasErrors property.
    Dim xTable As DataTable
    For Each xTable In xDataSet.Tables
        ' If HasErrors is true, reconcile errors.
        If xTable.HasErrors Then
            ' Insert code to reconcile errors.
        End If
    Next xTable
End Sub

[C#] 
private void CheckForErrors(DataSet myDataSet) {
   // Invoke GetChanges on the DataSet to create a reduced set.
   DataSet xDataSet = myDataSet.GetChanges();
   // Check each table's HasErrors property.
   foreach(DataTable xTable in xDataSet.Tables) {
      // If HasErrors is true, reconcile errors.
      if(xTable.HasErrors) {
         // Insert code to reconcile errors.
      }
   }
}

[C++] 
private:
 void CheckForErrors(DataSet* myDataSet) {
    // Invoke GetChanges on the DataSet to create a reduced set.
    DataSet* xDataSet = myDataSet->GetChanges();
    // Check each table's HasErrors property.
    System::Collections::IEnumerator* myEnum = xDataSet->Tables->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataTable* xTable = __try_cast<DataTable*>(myEnum->Current);
       // If HasErrors is true, reconcile errors.
       if(xTable->HasErrors) {
          // Insert code to reconcile errors.
       }
    }
 }

[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 | GetErrors

Show: