null reference

Discussion in 'ASP .Net' started by simon, Mar 24, 2005.

  1. simon

    simon Guest

    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, Mar 24, 2005
    #1
    1. Advertising

  2. simon

    Hans Kesting Guest

    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
    Hans Kesting, Mar 24, 2005
    #2
    1. Advertising

  3. simon

    simon Guest

    Thank you

    regards,
    Simon

    "Hans Kesting" <> wrote in message
    news:O%...
    > 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
    simon, Mar 24, 2005
    #3
  4. Hi,

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

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

    just like that

    bye

    "simon" <> wrote in message
    news:...
    > 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
    >
    >
    Michael Tkachev, Mar 24, 2005
    #4
  5. simon

    simon Guest

    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" <> wrote in message
    news:%...
    > Hi,
    >
    > Why do you check your session for DBNull???
    > DBNull is just for a database.
    >
    > if(Session[''aaa'] == null)
    >
    > just like that
    >
    > bye
    >
    > "simon" <> wrote in message
    > news:...
    >> 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, Mar 29, 2005
    #5
  6. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> Why do you check your session for DBNull???
    >> DBNull is just for a database.
    >>
    >> if(Session[''aaa'] == null)
    >>
    >> just like that
    >>
    >> bye
    >>
    >> "simon" <> wrote in message
    >> news:...
    >>> 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
    >>>
    >>>

    >>
    >>

    >
    >
    Juan T. Llibre, Mar 29, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,057
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,170
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    16
    Views:
    7,282
    Mike Schilling
    Oct 12, 2005
  4. Replies:
    5
    Views:
    26,476
    Mike Schilling
    Mar 29, 2006
  5. Bo Peng
    Replies:
    13
    Views:
    13,260
    Siemel Naran
    Jul 18, 2004
Loading...

Share This Page