System.Data Namespace DataRow Class
Checks whether there are errors in a row.
Script |
[ boolean var = ] DataRow.HasErrors |
This property returns only a boolean value: true if the row contains an error; otherwise, false.
The property is read only with no default value.
When validating data, you can set an error on any column in a row.
Use SetColumnError to set an error on any column.
Use the GetColumnError and GetColumnsInError methods to return columns with errors.
The ClearErrors method clears all errors for the row.
The following example first uses the HasErrors property to check for errors. If the row has errors, the GetColumnsInError method returns the array of columns with errors which can then be resolved. The ClearErrors method is then called to clear all errors.
private void GetAllErrs ( DataRow myRow ) {
// check if the row has errors
if ( myRow.HasErrors ) {
// get the array of columns in error.
DataColumn [ ] colArr = myRow.GetColumnsInError ( );
for ( int i = 0; i < colArr.Length; i++ ) {
// insert code to fix errors on each column.
Response.Write ( colArr [ ].ColumnName );
}
// clear errors after reconciling.
myRow.ClearErrors ( );
}
}
Private Sub GetAllErrs ( ByVal myRow As DataRow )
' check if the row has errors
If myRow.HasErrors Then
' get the array of columns in error.
Dim colArr ( ) As DataColumn = myRow.GetColumnsInError ( )
Dim i As Integer
For i = 0 to Ubound ( colArray )
' insert code to fix errors on each column.
Response.Write ( colArr ( i ).ColumnName )
Next i
' clear errors after reconciling.
myRow.ClearErrors ( )
End If
End Sub |
|
C# |
VB |
DataRow Members ClearErrors ColumnsCollection GetColumnError GetColumnsInError SetColumnError