469,889 Members | 1,382 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

null reference

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
Nov 19 '05 #1
5 1608
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
Nov 19 '05 #2
Thank you

regards,
Simon

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:O%****************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #3
Hi,

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

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

just like that

bye

"simon" <si*********@stud-moderna.si> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #4
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" <m_*******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

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

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

just like that

bye

"simon" <si*********@stud-moderna.si> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
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


Nov 19 '05 #5
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" <si*********@stud-moderna.si> wrote in message
news:Ok**************@TK2MSFTNGP12.phx.gbl...
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" <m_*******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

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

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

just like that

bye

"simon" <si*********@stud-moderna.si> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
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



Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Pablo J Royo | last post: by
3 posts views Thread by Marcus | last post: by
15 posts views Thread by JKop | last post: by
102 posts views Thread by junky_fellow | last post: by
6 posts views Thread by RMD | last post: by
2 posts views Thread by Fei Li | last post: by
27 posts views Thread by David W | last post: by
76 posts views Thread by valentin tihomirov | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.