sqlDataReader skipping first row in loop

  • Thread starter Thread starter branton ellerbee
  • Start date Start date
B

branton ellerbee

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?
 
Can you show the code? It sounds like you are calling/using something in the
wrong place.
 
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
 
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)
 
Back
Top