DataReader with 1 record...

S

Scott M.

I am familiar with DataReaders, but I am experiencing behavior I haven't
seen before.

I am using:

Dim dr as SQLClient.SQLClientDataReader
dr = command.ExecuteReader(CommandBehavior.SingleRow)

....and I am sure that the DataReader is returning 1 record (as it should).

What is troubling is that when I set watches on:

dr.Read()
dr.Item("x")
dr.Item("y")

I see that dr.Read() becomes True immedately after the command.ExecuteReader
statement (so far, so good). Now, my understanding is that "True" means
there is at least one more record to advance to, but at this point (not
having called dr.Read yet) I'm not actually on the first record yet.

What's strange is that at this point (again all I've done is
"ExecuteReader", didn't call dr.Read yet), the watches I have set up for
particular dr.Item values show up with the correct values! If it's true
that I am not on the first record yet, then why would I get these values at
this point.

Here's the next strange thing, after executing the next line of code after
"ExecuteReader", no matter what that line is, causes the dr.Read value to
become false and the dr.Item values to be thrown out!
 
S

Scott M.

As a follow up to my last message....

Everything stated in my first message is true WHEN A BREAKPOINT IS SET. As
soon as I turn off my breakpoints, all works as it should (I am aware of the
fact that the yellow shaded lines in break mode indicate what line is about
to run, not "has" run).
 
W

William \(Bill\) Vaughn

This is "by design". If you set a watch or execute a Read in an immediate
window, you are reading the row. If you read again, there are no more rows
(you said only return one).

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
R

Rodney Flowers

Datareaders are forward only. When you look at the value in the debug
window it would likely have to move to that record and then could not move
back to the current record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top