DataSet.HasErrors Property

Definition

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

[System.ComponentModel.Browsable(false)]
public bool HasErrors { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataSetHasErrorsDescr")]
public bool HasErrors { get; }

Property Value

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

Attributes

Examples

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.

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

private void PrintRowErrs(DataSet dataSet)
{
    foreach(DataTable table in dataSet.Tables)
    {
        foreach(DataRow row in table.Rows)
        {
            if(row.HasErrors)
            {
                Console.WriteLine(row.RowError);
            }
        }
    }
}

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.

Applies to

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also