473,748 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12370
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.Re ad
'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.Re ad() 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**@discussio ns.microsoft.co m> wrote in message
news:4F******** *************** ***********@mic rosoft.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.Re ad
'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
5211
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. ---------------------------------------------------------------------------- ---- 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...
2
2374
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" (I want to represent the count, but just a tempoary variable, not a field in table) doesnt exist in the table sqlStmt = "SELECT COUNT(*) As t FROM TimeSlot;" cmd = New SqlCommand(sqlStmt, conn) cmd.Connection.Open()
0
683
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. Aparently, when I select a person, it's not selecting anyone and returning this error. Here's the full error: Description: An unhandled exception occurred during the execution of the
15
2020
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 Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load Dim connectionString As String = "Data Source=server;Initial
4
3475
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 values I get "Invalid attempt to read when no data is present". private void GetLotIDPriorityFromLot(string aLotDesc, out int aLotID, out DateTime aPriorityDate) { SqlConnection Conn; SqlDataReader reader = null;
3
6529
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 share ur knowledge to help me out with this probs. my code is as below,
2
1759
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" keeps showing and i don't know why...i executed my stored procedure in the query analyzer and it's ok, i'm using the sentence "mydatareader.Read()" and it's working well....please, does anybody know what can i do?
2
6941
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 problem with this code: Invalid attempt to Read when reader is closed at line: While dtreader.Read() Thanks for help
1
1892
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 another page the script works yielding the desired records BUT WHEN YOU CALL THE SCRIPT AGAIN WHEN ATTEMPTING TO CALL THE SAME PAGE (PASSING DIFFERENT PARAMETERS USING QUERYSTRING ) THE QUERY DOESN'T YIELD ANY DATA Sub PropertyView( )
6
4989
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 trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. Source Error:
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.