System.Data Namespace DataTable Class
Returns an array of DataRow objects that contain errors.
[ VB ]
Public Function GetErrors ( ) As DataRow ( )
[ C# ]
public DataRow [ ] GetErrors ( );
[ C++ ]
public: DataRow* GetErrors ( ) [ ];
[ JScript ]
public function GetErrors ( ) : DataRow [ ];
An array of DataRow objects that have errors.
Invoke GetErrors after invoking the DataSet class's GetChanges method. Also, be sure you do not invoke the AcceptChanges on the DataTable until after all errors have been succesfully resolved, and the DataSet re-submitted for updating.
The following example uses the GetErrors method to return an array of DataRow objects that have errors.
Private void PrintAllErrs ( DataSet myDataSet ) {
DataRow [ ] rowsInError;
foreach ( DataTable myTable in myDataSet.Tables ) {
// test if the table has errors. If not, skip it.
if ( myTable.HasErrors ) {
// get an array of all rows with errors.
rowsInError = myTable.GetErrors ( );
// print the error of each column in each row.
for ( int i = 0; i < rowsInError.Length; i++ ) {
foreach ( DataColumn myCol in myTable.Columns ) {
Response.Write ( myCol.ColumnName + " " +
rowsInError [ ].GetColumnError ( myCol ) );
}
// clear the row errors
rowsInError [ ].ClearErrors ( );
}
}
}
}
Private Sub PrintAllErrs ( ByVal myDataSet As DataSet )
Dim rowsInError ( ) As DataRow, myTable As DataTable
Dim i As Integer, myCol As DataColumn
For Each myTable In myDataSet.Tables
' test if the table has errors. If not, skip it.
If myTable.HasErrors Then
' get an array of all rows with errors.
rowsInError = myTable.GetErrors ( )
' print the error of each column in each row.
For i = 0 To rowsInError.GetUpperBound ( 0 )
For Each myCol In myTable.Columns
Response.Write ( myCol.ColumnName, _
rowsInError ( i ).GetColumnError ( myCol ) )
Next
' clear the row errors
rowsInError ( i ).ClearErrors
Next i
End If
Next
End Sub |
|
C# |
VB |
DataTable Members AcceptChanges HasErrors RowError SetColumnError