all groups > asp.net > june 2004 >
You're in the

asp.net

group:

sqlDataReader skipping first row in loop


Re: sqlDataReader skipping first row in loop Ken Cox [Microsoft MVP]
6/1/2004 7:28:44 PM
asp.net:
Can you show the code? It sounds like you are calling/using something in the
wrong place.

[quoted text, click to view]
RE: sqlDataReader skipping first row in loop ranganh
6/1/2004 9:16:14 PM
hey

are you looping between the following code

while(DataReader1.Read




common mistake we make is, use

if(DataReader1.Read

and write the looping here


the problem is, if you use "if" then the reader's position is skipped to the first record and thereafter, if you d
some printing or reading stuff, it will read from the second record

hope it helps




----- branton ellerbee wrote: ----

I am looping through a datareader and building a table. However, no matte
what the resultset, the datareader skips the first row of data, then build
the rest of the resultset

I have seen this occur in a lot of different places since using .Net

HAs anyone else found this problem before



sqlDataReader skipping first row in loop branton ellerbee
6/1/2004 11:22:58 PM
I am looping through a datareader and building a table. However, no matter
what the resultset, the datareader skips the first row of data, then builds
the rest of the resultset.

I have seen this occur in a lot of different places since using .Net.

HAs anyone else found this problem before?


Re: sqlDataReader skipping first row in loop Teemu Keiski
6/2/2004 12:17:52 PM
If it is because of reading the first record as was explained, you can try a
loop like this:

if(SqlDataReader.Read)
{
do
{
//Do processing of the individual row here
}
while(SqlDataReader.Read);
}
else
{
//NO rows in SqlDataReader
}

With this you can check the existence of rows and still loop them one by
one(including the first one)
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

[quoted text, click to view]

AddThis Social Bookmark Button