J
Jay B. Harlow [MVP - Outlook]
J Jones,
Thinking about it, it may make more sense to have the syntax errors in your
result table or in an errors table, so that you can display them to the
user. Also I would consider logging the syntax errors, depending on who is
responsible for maintaining the Notes table in your SQL Server...
In which case you would need an ImportRow in the catch handler also.
Optionally setting the valid syntax field, something like:
Try
row!ValidSyntax = True
row!ValidSyntax = False
In the above example I am assuming that the dsNotes.Tables(0) datatable will
be discarded and modifying it will not cause problems, if this is not true,
then you will need to change the above code appropriately...
A word of caution, my sample code will treat problems with
"tableResult.ImportRow" as syntax errors, which may not be what you want...
I would consider modifying the code to be a little more robust (only catch
errors on the Select itself! however watch for reusing the exists variable
from the previous row ;-))
Hope this helps
Jay
Thinking about it, it may make more sense to have the syntax errors in your
result table or in an errors table, so that you can display them to the
user. Also I would consider logging the syntax errors, depending on who is
responsible for maintaining the Notes table in your SQL Server...
In which case you would need an ImportRow in the catch handler also.
Optionally setting the valid syntax field, something like:
Try
row!ValidSyntax = True
Catch ex As Exceptionexists = dtValues.Select(DirectCast(row!condition, String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
row!ValidSyntax = False
End TrytableResult.ImportRow(row)
In the above example I am assuming that the dsNotes.Tables(0) datatable will
be discarded and modifying it will not cause problems, if this is not true,
then you will need to change the above code appropriately...
A word of caution, my sample code will treat problems with
"tableResult.ImportRow" as syntax errors, which may not be what you want...
I would consider modifying the code to be a little more robust (only catch
errors on the Select itself! however watch for reusing the exists variable
from the previous row ;-))
Hope this helps
Jay
column.J Jones said:Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?
Private Sub Res()
Dim oBusinessLogic As New SurveyAdminLogic.BusinessLogic
Dim sXML1 As String
Dim sXML As String
Dim iReturn As Integer
Dim intResultIndex As Integer = CInt(txtSession.Text)
Try
sXML1 = oBusinessLogic.GetTraits(iReturn)
sXML = oBusinessLogic.GetScores(intResultIndex, iReturn)
Catch ex As Exception
End Try
oBusinessLogic = Nothing
Select Case iReturn
Case RETURN_SUCCESS
Dim dsValues As New DataSet
Dim dsNotes As New DataSet
Dim rValues As New System.IO.StringReader(sXML)
Dim rNotes As New System.IO.StringReader(sXML1)
Dim dtValues As New DataTable
Dim drValues As DataRow = dtValues.NewRow
Dim x As Integer = 0
dsValues.ReadXml(rValues)
dsNotes.ReadXml(rNotes)
dsValues.Tables.Add(dtValues)
While x < dsValues.Tables.Item(0).Rows.Count - 1
For Each row As DataRow In
dsValues.Tables.Item("Result").Rows
dtValues.Columns.Add(CStr(dsValues.Tables.Item(0).Rows.Item(x).Item(0)),
System.Type.GetType("System.Int32"))
x = x + 1
Next
End While
x = Nothing
dtValues.Rows.Add(drValues)
For x = 0 To dsValues.Tables.Item(0).Rows.Count - 1
dtValues.Rows.Item(0).Item(x) =
CInt(dsValues.Tables.Item(0).Rows.Item(x).Item(1))
Next
' tableResult contains the note rows that have a true
condition
Dim tableResult As DataTable = dsNotes.Tables(0).Clone()
Dim exists() As DataRow
For Each row As DataRow In dsNotes.Tables(0).Rows
exists = dtValues.Select(DirectCast(row!condition,
String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next
DataGrid1.DataSource = tableResult
DataGrid1.DataBind()
DataGrid1.Visible = True
End Select
End Sub