How to know total records selected?

Discussion in 'ASP .Net' started by anand, Jun 16, 2004.

  1. anand

    anand Guest

    Hello Group,
    How can i obtain the total no of records selected with the help of
    Datareader class. rowsaffected does not seem to work.


    anand, Jun 16, 2004
    1. Advertisements

  2. anand

    Patrice Guest

    A DataReader reads data as your code proceeds in the reading loop. Because
    of this, you can't know how much rows are returned until they are all

    If you don't need the number of rows before reading them :
    - count the rows in the reading loop

    If you need this number before reading the rows
    - issue a separate select count(*) statement to return the number of rows

    (The group should be enough)

    Patrice, Jun 16, 2004
    1. Advertisements

  3. Rowsafftected doesn't show you this. A reader doesn't know this number
    until the processing has been done, remember that it's a streambased
    mechanism. As such you'll either have to use a SELECT COUNT(*) statement
    before the real sql statement or you'll have to walk through the reader
    while(rdr.Read()){ i++;} The first method puts twice the stress on the db
    and is really not efficient. You can also consider using an Output

    Similarly, you can get this using a dataatable using the Rows.Count

    W.G. Ryan, eMVP
    William Ryan eMVP, Jun 16, 2004
  4. anand

    anand Guest

    Thanks a lot...

    anand, Jun 17, 2004
  5. anand

    anand Guest

    Thanks alot

    Anand :)
    anand, Jun 17, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.