problem with null data in sql

Discussion in 'ASP .Net' started by luna, Jan 28, 2004.

  1. luna

    luna Guest

    could someone explain the meaning behind :- System.IndexOutOfRangeException:
    firstname1

    when the code is :-

    If objDR("firstname1") Is System.DBNull.Value Then
    firstname1.Text = ""
    Else : firstname1.Text = objDR("fname1")
    End If


    and theres no entry in the database if theres an entry in the database there
    isnt a problem
     
    luna, Jan 28, 2004
    #1
    1. Advertisements

  2. luna

    Janaka Guest

    luna,

    I take it objDR is a DataReader? Try using its method of
    objDR.IsDBNull() - you'll have to use the ordinal number of "firstname1"
    instead.
    So your code will look more like:

    If objDR.IsDBNull(0) Then
    ....
    End If

    "luna" <> wrote in message
    news:ApNRb.169$...
    > could someone explain the meaning behind :-

    System.IndexOutOfRangeException:
    > firstname1
    >
    > when the code is :-
    >
    > If objDR("firstname1") Is System.DBNull.Value Then
    > firstname1.Text = ""
    > Else : firstname1.Text = objDR("fname1")
    > End If
    >
    >
    > and theres no entry in the database if theres an entry in the database

    there
    > isnt a problem
    >
    >
     
    Janaka, Jan 28, 2004
    #2
    1. Advertisements

  3. luna

    Dan Brussee Guest

    Your comment that there is no entry in the database makes me think
    that the objDR is empty, so there is no current record. This is very
    different than a field having a null value. Check if objDR is nothing
    (or null depending on language flavor) before testing. You should
    probably handle a null record differently than a null field value.

    On Wed, 28 Jan 2004 11:54:51 -0000, "luna" <> wrote:

    >could someone explain the meaning behind :- System.IndexOutOfRangeException:
    >firstname1
    >
    >when the code is :-
    >
    >If objDR("firstname1") Is System.DBNull.Value Then
    >firstname1.Text = ""
    >Else : firstname1.Text = objDR("fname1")
    >End If
    >
    >
    >and theres no entry in the database if theres an entry in the database there
    >isnt a problem
    >
     
    Dan Brussee, Jan 28, 2004
    #3
  4. luna

    luna Guest

    that did the trick thanks!!

    mark


    "Janaka" <> wrote in message
    news:...
    > luna,
    >
    > I take it objDR is a DataReader? Try using its method of
    > objDR.IsDBNull() - you'll have to use the ordinal number of "firstname1"
    > instead.
    > So your code will look more like:
    >
    > If objDR.IsDBNull(0) Then
    > ...
    > End If
    >
    > "luna" <> wrote in message
    > news:ApNRb.169$...
    > > could someone explain the meaning behind :-

    > System.IndexOutOfRangeException:
    > > firstname1
    > >
    > > when the code is :-
    > >
    > > If objDR("firstname1") Is System.DBNull.Value Then
    > > firstname1.Text = ""
    > > Else : firstname1.Text = objDR("fname1")
    > > End If
    > >
    > >
    > > and theres no entry in the database if theres an entry in the database

    > there
    > > isnt a problem
    > >
    > >

    >
    >
     
    luna, Jan 28, 2004
    #4
  5. luna

    luna Guest

    yes no entry in the database

    If objDR.IsDBNull(1) Then
    seems to do the trick

    thanks

    mark

    "Dan Brussee" <> wrote in message
    news:eek:...
    > Your comment that there is no entry in the database makes me think
    > that the objDR is empty, so there is no current record. This is very
    > different than a field having a null value. Check if objDR is nothing
    > (or null depending on language flavor) before testing. You should
    > probably handle a null record differently than a null field value.
    >
    > On Wed, 28 Jan 2004 11:54:51 -0000, "luna" <> wrote:
    >
    > >could someone explain the meaning behind :-

    System.IndexOutOfRangeException:
    > >firstname1
    > >
    > >when the code is :-
    > >
    > >If objDR("firstname1") Is System.DBNull.Value Then
    > >firstname1.Text = ""
    > >Else : firstname1.Text = objDR("fname1")
    > >End If
    > >
    > >
    > >and theres no entry in the database if theres an entry in the database

    there
    > >isnt a problem
    > >

    >
     
    luna, Jan 28, 2004
    #5
    1. Advertisements

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. Tommi Bauer

    SQL null problem

    Tommi Bauer, May 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    29,306
    Tommi Bauer
    May 17, 2004
  2. Mustafa Yesilkaya
    Replies:
    0
    Views:
    1,634
    Mustafa Yesilkaya
    Jun 11, 2004
  3. Kivak Wolf
    Replies:
    2
    Views:
    10,294
    Kivak Wolf
    Jun 28, 2005
  4. Replies:
    5
    Views:
    30,337
    Mike Schilling
    Mar 29, 2006
  5. Harry Zoroc
    Replies:
    1
    Views:
    1,172
    Gregory Vaughan
    Jul 12, 2004
  6. thersitz
    Replies:
    3
    Views:
    815
    thersitz
    Jan 31, 2007
  7. ecoolone
    Replies:
    0
    Views:
    946
    ecoolone
    Jan 3, 2008
  8. Ken Fine
    Replies:
    1
    Views:
    347
    Bob Barrows
    Nov 26, 2003
Loading...