473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1726
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
3
by: Marcus | last post by:
I'm running into a situation that has me adding a value of "Unknown" to a reference table. I am being pulled between two trains of thought, and was curious to get other's input on in. I give an...
15
by: JKop | last post by:
Does that Standard explicitly forbid the initiation of a null reference? Is there anything wrong with the following code?: void Blah( std::string const &k ) { if ( !&k ) return; // work with...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
6
by: RMD | last post by:
I need to be able to keep a list of object references, and null them out one by one at a later point in time. I realize this can be dangerous, but I have my reasons. I can't figure out, however,...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
2
by: Fei Li | last post by:
Hi, Is null value for a class instance allowed in C#? for example: MyClass obj = null; If Not, how to initiate an instance with value 0? How to detect if an instance is "newed" ? And how to...
27
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.