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.

    Thanks

    Anand
    anand, Jun 16, 2004
    #1
    1. Advertising

  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
    processed.

    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 ado.net group should be enough)

    -

    "anand" <> a écrit dans le message de
    news:uWM$...
    > Hello Group,
    > How can i obtain the total no of records selected with the help of
    > Datareader class. rowsaffected does not seem to work.
    >
    > Thanks
    >
    > Anand
    >
    >
    Patrice, Jun 16, 2004
    #2
    1. Advertising

  3. "anand" <> wrote in message
    news:uWM$...
    > Hello Group,
    > How can i obtain the total no of records selected with the help of
    > Datareader class. rowsaffected does not seem to work.


    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
    parameter.

    Similarly, you can get this using a dataatable using the Rows.Count
    property.
    >
    > Thanks
    >
    > Anand
    >
    >


    --

    W.G. Ryan, eMVP

    http://forums.devbuzz.com/
    http://www.knowdotnet.com/williamryan.html
    http://www.msmvps.com/WilliamRyan/
    William Ryan eMVP, Jun 16, 2004
    #3
  4. anand

    anand Guest

    Thanks a lot...

    Salute
    Anand
    "William Ryan eMVP" <> wrote in message
    news:#...
    >
    >
    >
    > "anand" <> wrote in message
    > news:uWM$...
    > > Hello Group,
    > > How can i obtain the total no of records selected with the help of
    > > Datareader class. rowsaffected does not seem to work.

    >
    > 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
    > parameter.
    >
    > Similarly, you can get this using a dataatable using the Rows.Count
    > property.
    > >
    > > Thanks
    > >
    > > Anand
    > >
    > >

    >
    > --
    >
    > W.G. Ryan, eMVP
    >
    > http://forums.devbuzz.com/
    > http://www.knowdotnet.com/williamryan.html
    > http://www.msmvps.com/WilliamRyan/
    >
    >
    anand, Jun 17, 2004
    #4
  5. anand

    anand Guest

    Thanks alot

    Salute
    Anand :)
    "Patrice" <> wrote in message
    news:...
    > 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
    > processed.
    >
    > 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 ado.net group should be enough)
    >
    > -
    >
    > "anand" <> a écrit dans le message de
    > news:uWM$...
    > > Hello Group,
    > > How can i obtain the total no of records selected with the help of
    > > Datareader class. rowsaffected does not seem to work.
    > >
    > > Thanks
    > >
    > > Anand
    > >
    > >

    >
    >
    anand, Jun 17, 2004
    #5
    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. Quentin Huo
    Replies:
    5
    Views:
    497
    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=
    Sep 1, 2004
  2. Sachin
    Replies:
    2
    Views:
    3,511
    =?Utf-8?B?UyBQ?=
    Mar 5, 2006
  3. Amelyan

    GridView: Total Records

    Amelyan, Mar 30, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    83,040
    AngelaG
    Oct 24, 2011
  4. Replies:
    2
    Views:
    7,292
    Bruno Alexandre
    Aug 23, 2006
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    216
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page