sqlDataReader skipping first row in loop

Discussion in 'ASP .Net' started by branton ellerbee, Jun 2, 2004.

  1. 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?
     
    branton ellerbee, Jun 2, 2004
    #1
    1. Advertising

  2. Can you show the code? It sounds like you are calling/using something in the
    wrong place.

    "branton ellerbee" <> wrote in message
    news:ld8vc.1819$...
    >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?
    >
    >
    >
     
    Ken Cox [Microsoft MVP], Jun 2, 2004
    #2
    1. Advertising

  3. 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
     
    =?Utf-8?B?cmFuZ2FuaA==?=, Jun 2, 2004
    #3
  4. branton ellerbee

    Teemu Keiski Guest

    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

    "branton ellerbee" <> wrote in message
    news:ld8vc.1819$...
    > 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?
    >
    >
    >
     
    Teemu Keiski, Jun 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Québec

    for loop skipping items

    Québec, Jul 30, 2004, in forum: C Programming
    Replies:
    7
    Views:
    395
    Keith Thompson
    Jul 31, 2004
  2. ray
    Replies:
    5
    Views:
    308
  3. Chris R.
    Replies:
    3
    Views:
    148
    Adam Prescott
    Jan 28, 2011
  4. Tad McClellan
    Replies:
    3
    Views:
    171
    Edward Wijaya
    May 13, 2004
  5. Isaac Won
    Replies:
    9
    Views:
    419
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page