473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datareader problem - read() returns true, but doesn't branch correctly

Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

....
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
....

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #1
5 1956
My first thought would be that code and debug information are out of sync
for some reason....

Try perhaps to delete the debug information to make sure you are using the
latest created... ??????

Patrice

--

"Scott Shuster" <sc***********@ yahoo.com> a écrit dans le message de
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

...
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
...

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #2
That's because your debug code is calling .Read, which executes, and
advances the cursor. Then your code tries to, but it's already been moved to
the first row. And presumably there is no second row, so the executing code
gets False after calling Read.

The debugger is executing stuff for real, since it has no way to execute
something like that on an object and rolling it back -it can't possible. So
you really need to be careful what you put in there.

"Scott Shuster" <sc***********@ yahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

...
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
...

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #3
Scott:
This is expected as far as i'm concerned...If you put objDR.Read() in your
watch, it'll actually execute objDR.Read() to see the result of that
function...whic h means that in your code, when you do objDR.Read() the
single row has already been read (by the debugger) and thus returns false...

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Scott Shuster" <sc***********@ yahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

...
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
...

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #4
Hiya

Datareader hasrows property might help some. I usually test to see is
hasrows = true , then read() off the datareader if there are indeed rows.

HTH Lerp

"Scott Shuster" <sc***********@ yahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

...
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
...

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #5
Hiya

Datareader hasrows property might help some. I usually test to see is
hasrows = true , then read() off the datareader if there are indeed rows.

HTH Lerp

"Scott Shuster" <sc***********@ yahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi,

I'm having some strange problems in VS employing a DataReader. Here's
a small snippet of the code:

...
objDR = objCMD.ExecuteR eader()
If objDR.Read() Then
(true stuff)
Else
(false stuff)
End If
...

For some reason, I'm getting to the Read() statement in debug mode and
it's showing 'True', but then it branches right to the (false) code.

If you think that's strange, here's where it gets worse. I get
different results if I execute it straight through, as opposed to
stepping through it line-by-line.

Has anyone else seen strange results in VS, using a DataReader, and
debugging?

Thanks,

Scott Shuster
sc***********@y ahoo.com

Nov 19 '05 #6

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

Similar topics

6
363
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader in ADO.NET in MSDN and there is a confusion regarding the buffering of data in case of DATAREADER. The link for MSDN JAN 2004 is -
6
11843
by: lakshmi | last post by:
Hi all I'm trying to traverse through the results from a query that returns more than 1 row. The data reader reads only the first row. The following code doesn't work. Let me know what's wrong. do { while(reader.read) { x += y;
20
5513
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to "clean up" the DataView once it is not referenced and will not effect the number of connections to the database. A DataReader on the other hand...
10
1846
by: Scott Richards | last post by:
Hi I am getting a exception while using a datareader here is the code Me.SqlConnection1.Open() Me.SqlReservationCheck.Parameters("@Ref").Value = Ref Dim Reader As SqlClient.SqlDataReader = _ Me.SqlReservationCheck.ExecuteReader() Dim I As Integer() Dim Index As Integer = 0 If Reader.HasRows Then While Reader.Read()
17
2368
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data, this method doesn't close it, it just returns the datareader. The calling code uses the datareader and then just lets it drop out of scope, to be...
3
9436
by: RSH | last post by:
Hi, I have a situation where I have two datareaders, and I want to make sure any given field from Datareader A exists in Datareader B before I can do anything with that column. I tried the code below but I get an exception thrown because the column doesn't exist in Datareader B. I'm not opposed to using another method but the same thing...
7
2899
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and returns N rows. DataReader object? Collection object? DataTable object? Returning a DataReader object is not a good practice...right? Thnks for all...
10
6091
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed...
2
2377
by: =?Utf-8?B?ZGJhMTIz?= | last post by:
Note, I'm using C# I am wondering what type of control I should use for iterating through the set of records returned by callin this method below, so that I can then do some stuff with each record like string manipulation, or taking the data for insertion into another table, etc.. Here's the function that returns the data as an ArrayList....
0
7520
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...
0
7718
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. ...
1
7470
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...
1
5368
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...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
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...
1
1936
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
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
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...

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.