Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > null reference

Reply
Thread Tools

null reference

 
 
simon
Guest
Posts: n/a
 
      03-24-2005
I use session:

If IsDBNull(Session("Source")) Then ' this is the line cause an error
bindRptSell()
End If

But I get an error message:

Object variable or With block variable not set.
System.NullReferenceException: Object variable or With block variable not
set.

Why? I check for null.

Simon


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      03-24-2005
simon wrote:
> I use session:
>
> If IsDBNull(Session("Source")) Then ' this is the line cause an error
> bindRptSell()
> End If
>
> But I get an error message:
>
> Object variable or With block variable not set.
> System.NullReferenceException: Object variable or With block variable not
> set.
>
> Why? I check for null.
>
> Simon
>
>


No, you check for "DbNull", which is DbNull.Value. This is *not* the
same as "null" (or "Nothing" in VB).

try:
If Session("Source") Is Nothing Then ...


--
Hans Kesting
 
Reply With Quote
 
 
 
 
simon
Guest
Posts: n/a
 
      03-24-2005
Thank you

regards,
Simon

"Hans Kesting" <(E-Mail Removed)> wrote in message
news:O%(E-Mail Removed)...
> simon wrote:
>> I use session:
>>
>> If IsDBNull(Session("Source")) Then ' this is the line cause an error
>> bindRptSell()
>> End If
>>
>> But I get an error message:
>>
>> Object variable or With block variable not set.
>> System.NullReferenceException: Object variable or With block variable not
>> set.
>>
>> Why? I check for null.
>>
>> Simon

>
> No, you check for "DbNull", which is DbNull.Value. This is *not* the same
> as "null" (or "Nothing" in VB).
>
> try:
> If Session("Source") Is Nothing Then ...
>
>
> --
> Hans Kesting



 
Reply With Quote
 
Michael Tkachev
Guest
Posts: n/a
 
      03-24-2005
Hi,

Why do you check your session for DBNull???
DBNull is just for a database.

if(Session[''aaa'] == null)

just like that

bye

"simon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I use session:
>
> If IsDBNull(Session("Source")) Then ' this is the line cause an error
> bindRptSell()
> End If
>
> But I get an error message:
>
> Object variable or With block variable not set.
> System.NullReferenceException: Object variable or With block variable not
> set.
>
> Why? I check for null.
>
> Simon
>
>



 
Reply With Quote
 
simon
Guest
Posts: n/a
 
      03-29-2005
Hi Michael,

If I use Session[''aaa'] =null I get the following error message:

'null' is not declared. 'Null' costant is no longer suported; use
'System.DBNull' instead.

So, that's way I'm using DBNull.

By the way, I'm writing in VB language. I heard that in C# that is possible,
to compare with null value.

Any comment?

Regards,
Simon

"Michael Tkachev" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> Why do you check your session for DBNull???
> DBNull is just for a database.
>
> if(Session[''aaa'] == null)
>
> just like that
>
> bye
>
> "simon" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I use session:
>>
>> If IsDBNull(Session("Source")) Then ' this is the line cause an error
>> bindRptSell()
>> End If
>>
>> But I get an error message:
>>
>> Object variable or With block variable not set.
>> System.NullReferenceException: Object variable or With block variable not
>> set.
>>
>> Why? I check for null.
>>
>> Simon
>>
>>

>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      03-29-2005
C# uses "null".

VB uses "Nothing".

Try

If IsNothing(Session("Source")) Then
....rest of code
End If

You could also set a variable equal to Session("Source")
and then the code would look a bit cleaner :

Dim varSource as String=Session("Source")
If IsNothing(varSource) Then
....rest of code
End If



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaņol
Ven, y hablemos de ASP.NET...
======================

"simon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Michael,
>
> If I use Session[''aaa'] =null I get the following error message:
>
> 'null' is not declared. 'Null' costant is no longer suported; use
> 'System.DBNull' instead.
>
> So, that's way I'm using DBNull.
>
> By the way, I'm writing in VB language. I heard that in C# that is
> possible, to compare with null value.
>
> Any comment?
>
> Regards,
> Simon
>
> "Michael Tkachev" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi,
>>
>> Why do you check your session for DBNull???
>> DBNull is just for a database.
>>
>> if(Session[''aaa'] == null)
>>
>> just like that
>>
>> bye
>>
>> "simon" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> I use session:
>>>
>>> If IsDBNull(Session("Source")) Then ' this is the line cause an error
>>> bindRptSell()
>>> End If
>>>
>>> But I get an error message:
>>>
>>> Object variable or With block variable not set.
>>> System.NullReferenceException: Object variable or With block variable
>>> not
>>> set.
>>>
>>> Why? I check for null.
>>>
>>> Simon
>>>
>>>

>>
>>

>
>



 
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
createImage sometime returns null and sometime returns non-null. vizlab Java 3 10-17-2007 11:21 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
difference between null object and null string gokul.b@gmail.com Java 16 10-12-2005 06:43 PM
VB.NET Null to SQL Null (ASP.NET 2.0 GridView) Kivak Wolf ASP .Net 2 06-28-2005 02:01 PM
Is there a null ostream (like /dev/null) in cpp? Bo Peng C++ 13 07-18-2004 07:17 PM



Advertisments