469,579 Members | 1,076 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Weird Null reference error problem

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
Oct 16 '07 #1
5 1358
try testing if r("qty_rem") is nothing first
"MattB" <so********@yahoo.comwrote in message
news:5n************@mid.individual.net...
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

Oct 16 '07 #2
Thanks for responding!
I'm doing that in this snippet below in the catch block and it passes
(it's not nothing). Then it errors where I'm assigning relevant info to
the session variable.
Any other ideas? I really do appreciate the response!

Matt

IfThenElse wrote:
try testing if r("qty_rem") is nothing first
"MattB" <so********@yahoo.comwrote in message
news:5n************@mid.individual.net...
>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

Oct 16 '07 #3

May be your ex.InnerException.Message is nothing. check it out.

I use,
If Not ( r("qty_rem") is nothing ) then
may be the same as NOT IsNothing(etc..)

"MattB" <so********@yahoo.comwrote in message
news:5n************@mid.individual.net...
Thanks for responding!
I'm doing that in this snippet below in the catch block and it passes
(it's not nothing). Then it errors where I'm assigning relevant info to
the session variable.
Any other ideas? I really do appreciate the response!

Matt

IfThenElse wrote:
>try testing if r("qty_rem") is nothing first
"MattB" <so********@yahoo.comwrote in message
news:5n************@mid.individual.net...
>>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
Oct 16 '07 #4
if it null in the database, r("qty_rem") returns DBNull, not null (nothing).

-- bruce (sqlwork.com)

MattB wrote:
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
Oct 17 '07 #5
good point

"bruce barker" <no****@nospam.comwrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
if it null in the database, r("qty_rem") returns DBNull, not null
(nothing).

-- bruce (sqlwork.com)

MattB wrote:
>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

Oct 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert Schott | last post: by
11 posts views Thread by HelLind | last post: by
reply views Thread by Deutsche Dogge | last post: by
16 posts views Thread by Paul S. Natanson | last post: by
2 posts views Thread by Flack | last post: by
27 posts views Thread by David W | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.