473,396 Members | 2,018 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,396 software developers and data experts.

Invalid attempt to read when no data is present

I'm using a datareader to get data from an sql table. The line that gives the
error is as follow,

dtrReceivers["Site_V"].ToString()

which gives the error,

Invalid attempt to read when no data is present

which is correct. The line works when data is in the row. But shouldn't the
data reader return a null! How can I check to see if data is in the row?

Thanks in advance,

David
Dec 21 '05 #1
4 12324
I get this error when I try to get the value of a column without first
calling the .Read method of the DataReader. Generally, you should
check the return from the .Read method:

While dtrReceivers.Read
'Read the values here
End While

..Read will return false when there are no more rows to read.

Dec 21 '05 #2
No, because it has no row to acquire a null value from. This is why
dtrReceivers.Read() returns a false when it is out of rows to read.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
I'm using a datareader to get data from an sql table. The line that gives
the
error is as follow,

dtrReceivers["Site_V"].ToString()

which gives the error,

Invalid attempt to read when no data is present

which is correct. The line works when data is in the row. But shouldn't
the
data reader return a null! How can I check to see if data is in the row?

Thanks in advance,

David

Dec 21 '05 #3
Thanks for the replys.

You are right there was no row being returned. There was a bug in my program
that I found that cause a invalid row to be selected. I thought that it was
giving the
error only when a valid row was being selected and reading the empty field,
since
it worked with one selection and not another.

Chris answer solved my problem, thanks.

"Chris Dunaway" wrote:
I get this error when I try to get the value of a column without first
calling the .Read method of the DataReader. Generally, you should
check the return from the .Read method:

While dtrReceivers.Read
'Read the values here
End While

..Read will return false when there are no more rows to read.

Dec 21 '05 #4
What you can do is check the DataReader's HasRows property. Then you
can handle the problem gracefully.

Dec 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brent Burkart | last post by:
Below is the error I am receiving. I have checked SQL Profiler and it is receiving the correct query which runs fine in Query Analyzer. Any ideas? Server Error in '/lockinsheet' Application....
2
by: Matthew Louden | last post by:
I want to read how many records in the table, and insert a record with id field which increment the counter by 1. However, I had the following runtime on Dim s As Integer = CInt(dr("t")). Since "t"...
0
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. ...
15
by: mosipenko | last post by:
I used to have a problem with DBNull, but now my issue is: System.InvalidOperationException: Invalid attempt to read when no data is present Here's my code behind: Private Sub...
4
by: MarkusR | last post by:
If I run the stored proc in the Query Analyzer this works and I get the expected result set back. However when I run it in my application I get a results set of one row but when I try to access the...
3
by: divsTiw | last post by:
I want to populate combo box with data from OracleDataReader , but "Invalid attempt to read when no data is present." is thrown. there are two rows returned , then too why such error. plzzz...
2
by: Naty | last post by:
please can anybody help me? i'm trying to retrieve data from a db with visual studio 2005 and sql server 2000 in a web application, and the error "Invalid attempt to read when no data is present"...
2
by: Chris | last post by:
Hi, i wrote this code for fetching data from a table using a stored procedure. The connection definition and opening are put in a class. The actual read of data occurs in code-behind. My...
1
Oodles Of Noodles
by: Oodles Of Noodles | last post by:
Hello fellow geeks I have a problem in my database iVB .Net program that is generating 'Error:Invalid attempt to read when no data is present.' The weird part is that when you call the page from...
6
by: =?Utf-8?B?ZWdzZGFy?= | last post by:
How can I solve this error: Invalid attempt to read when no data is present. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.