sqldatareader.read() is false with breakpoint

  • Thread starter Thread starter Marko Rangel
  • Start date Start date
M

Marko Rangel

I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the .Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

TIA
 
Marko Rangel said:
I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the ..Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

I think it's the Heisenberg uncertainty principle. Evaluating SqlDR.Read()
in the watch window advances the DataReader to the next record. The next
time you evaluate it, it has moved past the last record.

David
 
David:

Sorry for the stupid question, but what's his Uncertainty principle.? I'm
guessing it's the same Heisenberg that made the priceless quip about
Builders, Software Developers and what I woodpecker would be capable of...
It's off topic but it just piqued my interest.

TIA

Bill
David Browne said:
Marko Rangel said:
I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the .Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

I think it's the Heisenberg uncertainty principle. Evaluating SqlDR.Read()
in the watch window advances the DataReader to the next record. The next
time you evaluate it, it has moved past the last record.

David
 
What, never studied quantum mechanics or physics?
http://www.aip.org/history/heisenberg/p08.htm

Basically, he's implying that the closer you examine some things the more
they are affected by the fact that you're watching--thus their behavior is a
function of the fact they're being watched.
Heisenberg realized that the uncertainty relations had profound
implications. First, if we accept Heisenberg's argument that every concept
has a meaning only in terms of the experiments used to measure it, we must
agree that things that cannot be measured really have no meaning in physics.
Thus, for instance, the path of a particle has no meaning beyond the
precision with which it is observed. But a basic assumption of physics since
Newton has been that a "real world" exists independently of us, regardless
of whether or not we observe it. (This assumption did not go unchallenged,
however, by some philsophers.) Heisenberg now argued that such concepts as
orbits of electrons do not exist in nature unless and until we observe them.


--
____________________________________
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.
__________________________________

William Ryan said:
David:

Sorry for the stupid question, but what's his Uncertainty principle.? I'm
guessing it's the same Heisenberg that made the priceless quip about
Builders, Software Developers and what I woodpecker would be capable of...
It's off topic but it just piqued my interest.

TIA

Bill
David Browne said:
Marko Rangel said:
I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the .Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

I think it's the Heisenberg uncertainty principle. Evaluating SqlDR.Read()
in the watch window advances the DataReader to the next record. The next
time you evaluate it, it has moved past the last record.

David
 
Well, getting rid of checking for null did the trick. thanks to all.


David Browne said:
Marko Rangel said:
I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the .Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

I think it's the Heisenberg uncertainty principle. Evaluating SqlDR.Read()
in the watch window advances the DataReader to the next record. The next
time you evaluate it, it has moved past the last record.

David
 
What you might want is a test to see if the DataReader contains a rowset...
try
If (SQLDr.HasRows)
{

--
____________________________________
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.
__________________________________

Marko Rangel said:
Well, getting rid of checking for null did the trick. thanks to all.


David Browne said:
Marko Rangel said:
I have the following code:
if (SqlDR != null)
{
while (SqlDR.Read())
{
feed indexfeed = ReturnInstance();
indexfeed.FeedID = new Guid(SqlDR["ID"].ToString());
m_feedarr.Add(indexfeed);
}
}

When i put a breakpoint on (or before) the while line (SqlDR.Read()) the
code will not step inside the while loop, and the Watch window shows the
SqlRD.Read() as true. As soon as I reach that line and step into the next
line, the SqlRead.Read() turns to false and skips over the entire while
loop.

If I put the breakpoint in the while loop, the execution will actually stop
at the breakpoint in the loop.

The question is, why is it that I cannot put a breakpoint before the .Read()
on the while loop and step into the loop, but I can put a breakpoint inside
the while loop and hit the breakpoint on the same queries?

I think it's the Heisenberg uncertainty principle. Evaluating SqlDR.Read()
in the watch window advances the DataReader to the next record. The next
time you evaluate it, it has moved past the last record.

David
 
Back
Top