Public Shared Function TestDSForErrors(ByVal myDataSet As DataSet) As String
'Shared function makes it REALLY useful for debugging from VS Immed Window!
Dim SB As New Text.StringBuilder
Dim DT As DataTable
Dim DR As DataRow
Dim DC As DataColumn
Dim DRPos As Integer = 0
' Test for errors. If DataSet has errors, test each table.
If myDataSet.HasErrors Then
For Each DT In myDataSet.Tables
' If the table has errors, then print them.
If DT.HasErrors Then
DRPos = 0
SB.Append("Testing DataTable " & DT.TableName & ":" & vbCrLf)
For Each DR In DT.Rows
If DR.HasErrors Then
SB.Append(vbTab & "Row # " & DRPos & " error:" & DR.RowError & vbCrLf)
For Each DC In DR.GetColumnsInError
SB.Append(vbTab & vbTab & DC.ColumnName & " = " & CStr(DR.Item(DC.ColumnName)) & vbCrLf)
Next
'output row in error
SB.Append(vbTab & "Row data:" & PHSQLHelper.RowToString(DR) & vbCrLf)
SB.Append(vbTab & "Done with Row error:" & DR.RowError & vbCrLf)
End If
DRPos += 1
Next
SB.Append("Done Testing DataTable " & DT.TableName & ":" & vbCrLf & vbCrLf)
Else
SB.Append("DataTable " & DT.TableName & " has no errors." & vbCrLf)
End If
Next
Else
SB.Append("No errors detected in " & myDataSet.DataSetName & vbCrLf)
End If
Return SB.ToString
End Function
|