473,748 Members | 3,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Invalid attempt to read when no data is present"

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 GetLotIDPriorit yFromLot(string aLotDesc, out int aLotID,
out DateTime aPriorityDate)
{
SqlConnection Conn;
SqlDataReader reader = null;

aLotID = 0;
aPriorityDate = DateTime.Today;

Conn = new SqlConnection(" user id=myuserid;"
+"password=mypw d;"
+"server=myserv er;"
+"database=myda tabase;"
+"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd =
new SqlCommand("sp_ GetLotIDPriorit yFromLot",
Conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. Add(new SqlParameter("@ lot", aLotDesc));
reader = cmd.ExecuteRead er();

if (reader.HasRows )
{
--- aLotID =
Convert.ToInt32 (reader[0].ToString());
aPriorityDate =
Convert.ToDateT ime(reader[1].ToString());
}
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}

Any thoughts?

-Markus_R

Aug 31 '06 #1
4 3474
Markus_R,
It might help a lot if you put a catch block in there between the try and
the finally and output the exception Message and StackTrace properties, say,
to the output window with Debug.WriteLine .

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"MarkusR" wrote:
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 GetLotIDPriorit yFromLot(string aLotDesc, out int aLotID,
out DateTime aPriorityDate)
{
SqlConnection Conn;
SqlDataReader reader = null;

aLotID = 0;
aPriorityDate = DateTime.Today;

Conn = new SqlConnection(" user id=myuserid;"
+"password=mypw d;"
+"server=myserv er;"
+"database=myda tabase;"
+"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd =
new SqlCommand("sp_ GetLotIDPriorit yFromLot",
Conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. Add(new SqlParameter("@ lot", aLotDesc));
reader = cmd.ExecuteRead er();

if (reader.HasRows )
{
--- aLotID =
Convert.ToInt32 (reader[0].ToString());
aPriorityDate =
Convert.ToDateT ime(reader[1].ToString());
}
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}

Any thoughts?

-Markus_R

Aug 31 '06 #2
Hey Peter,

It looks like I need:

reader.Read();

above:
if (reader.HasRows )

I had to close/reopen VS2005 before even that would take. VS2005 must
have been in a bad mood. I even tried build/rebuild.

-Markus

Peter wrote:
Markus_R,
It might help a lot if you put a catch block in there between the try and
the finally and output the exception Message and StackTrace properties, say,
to the output window with Debug.WriteLine .

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"MarkusR" wrote:
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 GetLotIDPriorit yFromLot(string aLotDesc, out int aLotID,
out DateTime aPriorityDate)
{
SqlConnection Conn;
SqlDataReader reader = null;

aLotID = 0;
aPriorityDate = DateTime.Today;

Conn = new SqlConnection(" user id=myuserid;"
+"password=mypw d;"
+"server=myserv er;"
+"database=myda tabase;"
+"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd =
new SqlCommand("sp_ GetLotIDPriorit yFromLot",
Conn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.Parameters. Add(new SqlParameter("@ lot", aLotDesc));
reader = cmd.ExecuteRead er();

if (reader.HasRows )
{
--- aLotID =
Convert.ToInt32 (reader[0].ToString());
aPriorityDate =
Convert.ToDateT ime(reader[1].ToString());
}
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}

Any thoughts?

-Markus_R
Aug 31 '06 #3
On 31 Aug 2006 14:29:52 -0700, "MarkusR" <ma*******@gmai l.comwrote:
>Hey Peter,

It looks like I need:

reader.Read();

above:
if (reader.HasRows )
<snip>

If you put it above if(reader.HasRo ws), it will throw an error if there are no
rows. It should be like this:

If(reader.HasRo ws)
{
reader.Read();
..
..
..
}
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Sep 1 '06 #4
thanks Otis.

-Markus_R

Otis Mukinfus wrote:
On 31 Aug 2006 14:29:52 -0700, "MarkusR" <ma*******@gmai l.comwrote:
Hey Peter,

It looks like I need:

reader.Read();

above:
if (reader.HasRows )
<snip>

If you put it above if(reader.HasRo ws), it will throw an error if there are no
rows. It should be like this:

If(reader.HasRo ws)
{
reader.Read();
.
.
.
}
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Sep 13 '06 #5

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

Similar topics

1
4800
by: wiredog | last post by:
When I try to add the line . . . CPM * MOU AS COST, after all the CASE lines I get the response in SQL Query Analyser, Server: Msg 207, Level 16, State 3, Line 1 Invalid column name 'CPM'. Is it because I can not do this on this particular query since CPM is
3
3011
by: Stephen Poley | last post by:
Could some kind soul explain the errors and warnings that the W3C CSS validator generates for page: http://www.atlis.nl/testsite/nl/ Results at: http://tinyurl.com/5pxqx The error "Invalid number : borderParse Error - " may be due to something I've done, but I'm blowed if I can see what. While the warning "property display doesn't exist for media" has me baffled.
0
1939
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application opening the file... Code: function UTIL_ForceDownloadFile(strFileName, strFileSaveName) Response.Buffer = True Dim strFileSize Const adTypeBinary = 1
0
1007
by: John Hunter | last post by:
I've recently had a nasty problem with the "Invalid reference to the property Form" error in subforms - nasty because it doesn't seem to consistently happen to all forms which contain the same structure and code. Judging by the forums I've researched, it's not an uncommon error. I'm happy to say I've found a simple solution. OVERVIEW: I have a main form (no record source) which contains two subforms. The subforms are not linked, but...
0
1580
by: Ray | last post by:
Dear all, I successfully deploy a window application with crystal report. However, while using exporting function of the CrystalReportViewer, there is an error "Invalid export DLL. or export format". Please help. Thanks a lot, Ray
3
4530
by: blackpuppy | last post by:
I am just beginner on PHP. I am reading "Spring Into PHP 5" but cannot make the ftp examples work. I am running PHP scripts on a Fedora Core 5 (VMWare virtual machine) on top of a Windows XP Professional. The PHP version is 5.1.4. The PHP script is shown below. #! /usr/bin/php <?php $ftp_server = "myftpserver";
5
2170
by: veaux | last post by:
I'm thinking this is easy but can't get it. I have a table with following: Table1 Date 1/1/2007 Table2 Type 0107 (This is MMYY of above) So I'm having trouble using a query to turn the date from Table 1 into
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,
15
3004
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy Tubbs
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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
4599
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...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.