System.Data Namespace DataTable Class
Checks whether there are errors in any of the rows in any of the tables of the DataSet to which the table belongs.
Script |
[ bool variable = ] DataTable.HasErrors |
This property returns only a boolean value: true if errors exist, otherwise, false.
The property is read only with no default value.
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 DBMS 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 DBMS 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.
The following example uses the HasErrors property to check if a table contains errors.
Private void HasErrorsDemo ( 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.
}
}
}
Private Sub HasErrorsDemo ( 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# |
VB |
DataTable Members GetErrors