Don't Understand This error?

Discussion in 'ASP .Net' started by Wayne Wengert, Mar 3, 2005.

  1. I am using a datareader (dr1) to read through rows returned from a query. I
    am getting the error: "No data exists for the row/column." at the "If
    IsDbNull..." in the code below. The field "Photo1" does exist and in some
    rows it is null, in others it may be an empty string and in others it may
    have a file name. I don't understand exactly what the system is complaining
    about here?

    Wayne



    =========== code ============
    If IsDBNull(dr1.Item("Photo2")) Then

    txtPhoto2.Text = ""

    Else

    txtPhoto2.Text = dr1.Item("Photo2")

    End If
     
    Wayne Wengert, Mar 3, 2005
    #1
    1. Advertising

  2. Did you do a dr1.Read() first?

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Wayne Wengert" <> wrote in message
    news:...
    >I am using a datareader (dr1) to read through rows returned from a query. I
    > am getting the error: "No data exists for the row/column." at the "If
    > IsDbNull..." in the code below. The field "Photo1" does exist and in some
    > rows it is null, in others it may be an empty string and in others it may
    > have a file name. I don't understand exactly what the system is
    > complaining
    > about here?
    >
    > Wayne
    >
    >
    >
    > =========== code ============
    > If IsDBNull(dr1.Item("Photo2")) Then
    >
    > txtPhoto2.Text = ""
    >
    > Else
    >
    > txtPhoto2.Text = dr1.Item("Photo2")
    >
    > End If
    >
    >
     
    Steve C. Orr [MVP, MCSD], Mar 3, 2005
    #2
    1. Advertising

  3. Where's the complete code, are you doing a while dr1.Read() before you check
    for null?


    While dr1.Read()
    If IsDBNull(dr1.Item("Photo2")) Then
    End


    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Wayne Wengert" <> wrote in message
    news:...
    > I am using a datareader (dr1) to read through rows returned from a query.

    I
    > am getting the error: "No data exists for the row/column." at the "If
    > IsDbNull..." in the code below. The field "Photo1" does exist and in some
    > rows it is null, in others it may be an empty string and in others it may
    > have a file name. I don't understand exactly what the system is

    complaining
    > about here?
    >
    > Wayne
    >
    >
    >
    > =========== code ============
    > If IsDBNull(dr1.Item("Photo2")) Then
    >
    > txtPhoto2.Text = ""
    >
    > Else
    >
    > txtPhoto2.Text = dr1.Item("Photo2")
    >
    > End If
    >
    >
     
    Manohar Kamath, Mar 3, 2005
    #3
  4. If a column in a row doesn't exist, then IsDbNull will not be able to
    evaluate the contents of the cell because there aren't any contents of the
    cell. If the field doesn't exist you need to catch the
    IndexOutOfRangeException exception that it will throw. Remember, a null
    value in a database is a special value being passed from the db and not the
    same as a null used in typical programming languages.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - FrontPage



    "Wayne Wengert" <> wrote in message
    news:...
    >I am using a datareader (dr1) to read through rows returned from a query. I
    > am getting the error: "No data exists for the row/column." at the "If
    > IsDbNull..." in the code below. The field "Photo1" does exist and in some
    > rows it is null, in others it may be an empty string and in others it may
    > have a file name. I don't understand exactly what the system is
    > complaining
    > about here?
    >
    > Wayne
    >
    >
    >
    > =========== code ============
    > If IsDBNull(dr1.Item("Photo2")) Then
    >
    > txtPhoto2.Text = ""
    >
    > Else
    >
    > txtPhoto2.Text = dr1.Item("Photo2")
    >
    > End If
    >
    >
     
    Mark Fitzpatrick, Mar 3, 2005
    #4
  5. Yes, that code is in a read loop

    Wayne

    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:...
    > Did you do a dr1.Read() first?
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
    > "Wayne Wengert" <> wrote in message
    > news:...
    > >I am using a datareader (dr1) to read through rows returned from a query.

    I
    > > am getting the error: "No data exists for the row/column." at the "If
    > > IsDbNull..." in the code below. The field "Photo1" does exist and in

    some
    > > rows it is null, in others it may be an empty string and in others it

    may
    > > have a file name. I don't understand exactly what the system is
    > > complaining
    > > about here?
    > >
    > > Wayne
    > >
    > >
    > >
    > > =========== code ============
    > > If IsDBNull(dr1.Item("Photo2")) Then
    > >
    > > txtPhoto2.Text = ""
    > >
    > > Else
    > >
    > > txtPhoto2.Text = dr1.Item("Photo2")
    > >
    > > End If
    > >
    > >

    >
    >
     
    Wayne Wengert, Mar 3, 2005
    #5
  6. The "complete code" is over 600 lines with may subs and functions being
    called. I am getting suspicious that I may have a call to a sub that closes
    the reader - I'll put in some brakes to see if I can isolate it.

    Wayne

    "Manohar Kamath" <> wrote in message
    news:...
    > Where's the complete code, are you doing a while dr1.Read() before you

    check
    > for null?
    >
    >
    > While dr1.Read()
    > If IsDBNull(dr1.Item("Photo2")) Then
    > End
    >
    >
    > --
    > Manohar Kamath
    > Editor, .netWire
    > www.dotnetwire.com
    >
    >
    > "Wayne Wengert" <> wrote in message
    > news:...
    > > I am using a datareader (dr1) to read through rows returned from a

    query.
    > I
    > > am getting the error: "No data exists for the row/column." at the "If
    > > IsDbNull..." in the code below. The field "Photo1" does exist and in

    some
    > > rows it is null, in others it may be an empty string and in others it

    may
    > > have a file name. I don't understand exactly what the system is

    > complaining
    > > about here?
    > >
    > > Wayne
    > >
    > >
    > >
    > > =========== code ============
    > > If IsDBNull(dr1.Item("Photo2")) Then
    > >
    > > txtPhoto2.Text = ""
    > >
    > > Else
    > >
    > > txtPhoto2.Text = dr1.Item("Photo2")
    > >
    > > End If
    > >
    > >

    >
    >
     
    Wayne Wengert, Mar 3, 2005
    #6
  7. I'm using the same code in my software and it works like a champ.
    This leads me to believe that maybe you don't actually have a "Photo2"
    column in your result set as you think you do.
    Try this experiment, use the numeric index of the data column instead of the
    column name, such as this:
    If IsDBNull(dr1.Item(0)) Then...

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net



    "Wayne Wengert" <> wrote in message
    news:...
    > Yes, that code is in a read loop
    >
    > Wayne
    >
    > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > news:...
    >> Did you do a dr1.Read() first?
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr, MCSD, MVP
    >> http://SteveOrr.net
    >>
    >>
    >> "Wayne Wengert" <> wrote in message
    >> news:...
    >> >I am using a datareader (dr1) to read through rows returned from a
    >> >query.

    > I
    >> > am getting the error: "No data exists for the row/column." at the "If
    >> > IsDbNull..." in the code below. The field "Photo1" does exist and in

    > some
    >> > rows it is null, in others it may be an empty string and in others it

    > may
    >> > have a file name. I don't understand exactly what the system is
    >> > complaining
    >> > about here?
    >> >
    >> > Wayne
    >> >
    >> >
    >> >
    >> > =========== code ============
    >> > If IsDBNull(dr1.Item("Photo2")) Then
    >> >
    >> > txtPhoto2.Text = ""
    >> >
    >> > Else
    >> >
    >> > txtPhoto2.Text = dr1.Item("Photo2")
    >> >
    >> > End If
    >> >
    >> >

    >>
    >>

    >
    >
     
    Steve C. Orr [MVP, MCSD], Mar 3, 2005
    #7
  8. Found it!

    I had a sub that closed the reader under certain conditions. That was
    causing the error. Fixed the logic and now it is working.

    I appreciate the suggestions.

    Wayne

    "Wayne Wengert" <> wrote in message
    news:...
    > I am using a datareader (dr1) to read through rows returned from a query.

    I
    > am getting the error: "No data exists for the row/column." at the "If
    > IsDbNull..." in the code below. The field "Photo1" does exist and in some
    > rows it is null, in others it may be an empty string and in others it may
    > have a file name. I don't understand exactly what the system is

    complaining
    > about here?
    >
    > Wayne
    >
    >
    >
    > =========== code ============
    > If IsDBNull(dr1.Item("Photo2")) Then
    >
    > txtPhoto2.Text = ""
    >
    > Else
    >
    > txtPhoto2.Text = dr1.Item("Photo2")
    >
    > End If
    >
    >
     
    Wayne Wengert, Mar 3, 2005
    #8
  9. Re: Found it!

    Yeah working with Reader is a pain the Ass sometimes!!



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Patrick Olurotimi Ige, Mar 3, 2005
    #9
  10. Re: Found it!

    Being an old fart with limited skills doesn't help either <smirk!>

    Wayne

    "Patrick Olurotimi Ige" <> wrote in message
    news:%...
    > Yeah working with Reader is a pain the Ass sometimes!!
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Wayne Wengert, Mar 3, 2005
    #10
  11. Re: Found it!

    Can u please explain what a sub means and how the sub was responsible
    for the error. I am in a similar situation and not able to understand
    how the exception is thrown.

    George


    *** Sent via Developersdex http://www.developersdex.com ***
     
    George Christopher, Jan 4, 2006
    #11
    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. simon

    Error message I don't understand

    simon, Dec 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    317
    Hatim R
    Dec 5, 2003
  2. m miller

    don't understand error

    m miller, Jan 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,736
    smitdso
    Sep 8, 2006
  3. Wayne Wengert

    Don't Understand error

    Wayne Wengert, Nov 26, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    464
    Wayne Wengert
    Dec 4, 2005
  4. Tobias Langner

    compiler error I don't understand

    Tobias Langner, Aug 1, 2003, in forum: C++
    Replies:
    7
    Views:
    330
    Jakob Bieling
    Aug 1, 2003
  5. Chris Saunders

    Don't understand syntax error

    Chris Saunders, May 16, 2005, in forum: C Programming
    Replies:
    9
    Views:
    476
    CBFalconer
    May 17, 2005
Loading...

Share This Page