System.Data Namespace DataSet Class
Checks whether there are errors in any of the rows in any of the tables of this DataSet.
Script |
DataSet.HasErrors [ = true | false ]
|
This property returns only a boolean value: true if any table has errors; otherwise, false.
The property is read only with no default value.
The HasErrors property is usually consulted after creating using the GetChanges method. Check the HasErrors property of the DataSet created with the GetChanges method to determine if any errors exists. If so, you should reconcile the errors before proceeding to update the data source with the changes.
Each DataTable in a DataSet also has a HasErrors property. Use the DataSet object's HasErrors 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 that have errors.
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 ( !myDataSet.HasErrors ) {
myDataSet.Merge ( mainDataSet );
}
else {
PrintRowErrs ( myDataSet );
}
}
private void PrintRowErrs ( DataSet myDataSet ) {
foreach ( DataTable myTable in myDataSet.Tables ) {
foreach ( DataRow myRow in myTable.Rows ) {
if ( myRow.HasErrors ) {
Response.Write ( myRow.RowError );
}
}
}
}
Private Sub CheckForErrors ( )
If Not myDataSet.HasErrors Then
myDataSet.Merge ( mainDataSet )
Else
PrintRowErrs ( myDataSet )
End If
End Sub
Private Sub PrintRowErrs ( ByVal myDataSet As DataSet )
Dim myTable As DataTable
For Each myTable In myDataSet.Tables
Dim myRow As DataRow
For Each myRow In myTable.Rows
If myRow.HasErrors Then
Response.Write ( myRow.RowError )
End If
Next
Next
End Sub |
|
C# |
VB |
DataSet Members GetChanges HasChanges