Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Don't Understand This error?

Reply
Thread Tools

Don't Understand This error?

 
 
Wayne Wengert
Guest
Posts: n/a
 
      03-03-2005
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


 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      03-03-2005
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
>
>



 
Reply With Quote
 
 
 
 
Manohar Kamath
Guest
Posts: n/a
 
      03-03-2005
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
>
>



 
Reply With Quote
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      03-03-2005
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
>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-03-2005
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
> >
> >

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-03-2005
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
> >
> >

>
>



 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      03-03-2005
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
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-03-2005
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
>
>



 
Reply With Quote
 
Patrick Olurotimi Ige
Guest
Posts: n/a
 
      03-03-2005
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!
 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      03-03-2005
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!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
an error on multi-source, but I can't understand... Neil VHDL 11 03-11-2010 03:15 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
understand Mozilla Thunderbird files... Joh Firefox 6 12-11-2004 11:46 PM
Configure & understand radius Julien Cisco 0 06-07-2004 09:12 AM
how to read and understand long written VHDL code? walala VHDL 6 09-03-2003 07:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57