Export (0) Print
Expand All

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.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

[BrowsableAttribute(false)]
public bool HasErrors { get; }

Property Value

Type: System.Boolean
true if errors exist; otherwise false.

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.

The following example uses the HasErrors property to check if a table contains errors.

private void CheckForErrors(DataSet dataSet) 
{
    // Invoke GetChanges on the DataSet to create a reduced set.
    DataSet thisDataSet = dataSet.GetChanges();

    // Check each table's HasErrors property. 
    foreach(DataTable table in thisDataSet.Tables) 
    {
        // If HasErrors is true, reconcile errors. 
        if(table.HasErrors) 
        {
            // Insert code to reconcile errors.
        }
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft