Represents an custom error that can be associated with a DataRow.
Object
DataError
[Visual Basic] Public Class DataError [C#] public class DataError [C++] public __gc class DataError [JScript] public class DataError
Custom error messages allow you to give your end users a non-technical error message for each row in a table. For example, you can use the GetColumnsInError to determine exactly which column has an error, and insert the information into the DataError. In a System.WinForms.DataGrid control, any rows that have an error is marked with a red exclamation mark, allowing the user to scan for errors quickly.
To set custom error text, create a DataError, and assign the object to the Error property of a DataRow.
Use the DataSet object's HasErrors property to check if any table has an error. If so, retrieve the DataError for each DataRow through the RowError property.
Namespace: System.Data
Assembly: System.Data.dll
The following example sets DataError objects for ten rows in a table; the example also prints each error out.
[Visual Basic]
Private Sub SetErrors() Dim t As DataTable ' Get the DataTable of a DataGrid control. Set t = DataGrid1.DataGridTable.DataTable Dim i As Integer Dim de As DataError ' Create 10 DataError objects and assign to ten rows. Insert column 1 value into error. For i = 1 To 10 Set de = New DataError("ERROR: " & t.rows(i)(1)) Set t.Rows(i).Error = de Next Dim ds As DataSet Set ds = t.DataSet Dim tempT As DataTable ' Test for errors. If DataSet has errors, test each table. If Not ds.HasErrors Then ' If you have no errors, you can merge the DataSet with it's clone. ' DataSet1.Merge DataSetClone Else For Each tempT In ds.Tables ' If the table has errors, then print them. If tempT.HasErrors Then printRowErrs tempT Next End If ' Refresh the DataGrid to see the error-marked rows. DataGrid1.Refresh End Sub Private Sub PrintRowErrs(t As DataTable) Dim r As DataRow For Each r In t.Rows If r.HasErrors Then Debug.Print r.RowError End If Next End Sub