Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Weird Null reference error problem

Reply
Thread Tools

Weird Null reference error problem

 
 
MattB
Guest
Posts: n/a
 
      10-16-2007
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
 
Reply With Quote
 
 
 
 
IfThenElse
Guest
Posts: n/a
 
      10-16-2007
try testing if r("qty_rem") is nothing first


"MattB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
MattB
Guest
Posts: n/a
 
      10-16-2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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

>
>

 
Reply With Quote
 
IfThenElse
Guest
Posts: n/a
 
      10-16-2007

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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

>>


 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      10-16-2007
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

 
Reply With Quote
 
IfThenElse
Guest
Posts: n/a
 
      10-17-2007
good point

"bruce barker" <(E-Mail Removed)> wrote in message
news:eKp$h$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPX page jscript rt error: null is null or not an object Cirene ASP .Net 1 06-09-2008 07:59 PM
"Object reference not set to an instance of an object" Weird thing happens with reference a link nguyentrongkha@gmail.com ASP .Net 1 09-20-2007 09:46 PM
newbie with a weird technical problem (@ least I think it's weird) will Ruby 6 12-27-2006 04:46 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
sometimes we get Object reference to NULL error blash ASP .Net 6 12-29-2004 05:31 AM



Advertisments