M
MattB
I'm relatively familiar with asp.net and vb.net and have been working in
the environment for several years. I've dealt with null reference errors
before and generally know how to code around them
But now I have some new code I deployed and I'm getting a null reference
error when looping through a datatable (for each r in dt.rows...).
I'm expecting to find an integer in this field, or possibly nothing, or
possibly a dash (-).
So I added some extra stuff to figure out what's in there (I don;t have
access to the same dataset where this is running, or I'd just use the
debugger). I made this block of code to help me figure it out:
If IsNumeric(Trim(r("qty_rem"))) Then 'Trim(r("qty_rem")) <> "-" And
Trim(r("qty_rem")) <> "" Then
Dim iRem As Int16
Try
iRem = Convert.ToInt16(Trim(r("qty_rem")))
Catch ex As Exception
If Not IsNothing(r("qty_rem")) Then
Current.Session("lastError") = "r(qty_rem) = '" & r("qty_rem") & "'"
& vbCrLf & ex.Message & vbCrLf & ex.InnerException.Message
Current.Response.Redirect("error.aspx")
Else
Current.Session("lastError") = "r(qty_rem) is nothing" & vbCrLf &
ex.Message & vbCrLf & ex.InnerException.Message
Current.Response.Redirect("error.aspx")
End If
End Try
And now instead of redirecting to my error page and showing me what is
in there, it crashes on the line where it tries to assign values to the
"lastError" session variable. But it passes If not isNothing() and
IsNumeric(). I don't get it. Can anyone see the problem in finding out
what is in this dataset? Thanks!
Matt
the environment for several years. I've dealt with null reference errors
before and generally know how to code around them
But now I have some new code I deployed and I'm getting a null reference
error when looping through a datatable (for each r in dt.rows...).
I'm expecting to find an integer in this field, or possibly nothing, or
possibly a dash (-).
So I added some extra stuff to figure out what's in there (I don;t have
access to the same dataset where this is running, or I'd just use the
debugger). I made this block of code to help me figure it out:
If IsNumeric(Trim(r("qty_rem"))) Then 'Trim(r("qty_rem")) <> "-" And
Trim(r("qty_rem")) <> "" Then
Dim iRem As Int16
Try
iRem = Convert.ToInt16(Trim(r("qty_rem")))
Catch ex As Exception
If Not IsNothing(r("qty_rem")) Then
Current.Session("lastError") = "r(qty_rem) = '" & r("qty_rem") & "'"
& vbCrLf & ex.Message & vbCrLf & ex.InnerException.Message
Current.Response.Redirect("error.aspx")
Else
Current.Session("lastError") = "r(qty_rem) is nothing" & vbCrLf &
ex.Message & vbCrLf & ex.InnerException.Message
Current.Response.Redirect("error.aspx")
End If
End Try
And now instead of redirecting to my error page and showing me what is
in there, it crashes on the line where it tries to assign values to the
"lastError" session variable. But it passes If not isNothing() and
IsNumeric(). I don't get it. Can anyone see the problem in finding out
what is in this dataset? Thanks!
Matt