null reference

S

simon

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
 
H

Hans Kesting

simon said:
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 ...
 
S

simon

Thank you

regards,
Simon

Hans Kesting said:
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 ...
 
M

Michael Tkachev

Hi,

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

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

just like that

bye
 
S

simon

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 said:
Hi,

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

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

just like that

bye

simon said:
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
 
J

Juan T. Llibre

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





simon said:
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 said:
Hi,

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

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

just like that

bye

simon said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top