When working with individual columns and rows of data, there may be times when a record contains an error. You can Check the HasErrors property to determine if errors exist in a DataSet, DataTable, or DataRow.
To locate a row that has errors
-
Check the HasErrors property to see if there are any errors in the dataset.
-
If the HasErrors property is true, iterate through the collections of tables, then the rows to find the row with the error.
Private Sub FindErrors()
Dim table As Data.DataTable
Dim row As Data.DataRow
If DataSet1.HasErrors Then
For Each table In DataSet1.Tables
If table.HasErrors Then
For Each row In table.Rows
If row.HasErrors Then
' Process error here.
End If
Next
End If
Next
End If
End Sub
private void FindErrors()
{
if (dataSet1.HasErrors)
{
foreach (DataTable table in dataSet1.Tables)
{
if (table.HasErrors)
{
foreach (DataRow row in table.Rows)
{
if (row.HasErrors)
{
// Process error here.
}
}
}
}
}
}
private void Find_Errors()
{
if (dataSet1.get_HasErrors())
{
// for each table
for (int i = 0; i < dataSet1.get_Tables().get_Count(); i++)
{
DataTable table = dataSet1.get_Tables().get_Item(i);
if (table.get_HasErrors())
{
// for each row
for (int j = 0; j < table.get_Rows().get_Count(); j++)
{
DataRow row = table.get_Rows().get_Item(j);
if (row.get_HasErrors())
{
// Process error here.
}
}
}
}
}
}
See Also