null reference

  • Thread starter Thread starter simon
  • Start date Start date
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
 
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 ...
 
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 ...
 
Hi,

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

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

just like that

bye
 
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
 
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 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
 
Back
Top