Re: Using DataReader to count rows
- From: "Marina" <someone@xxxxxxxxxx>
- Date: Tue, 24 May 2005 14:49:40 -0400
The loop you have there does work. I don't know what you are doing
beforehand so that it end up not working, but that technique in general will
work.
A faster technique is to do a coutn(*) in your query, to get the number of
rows, instead of tediously going through the result set. You would see the
performance much improved.
And yet another option is to use a datatable, which is an in memory copy of
the result set, and gives you instantenous access to any row in the result
set, as well as the count.
"Steve Wolfie" <stevewolfie@xxxxxxxxxxxxxxxx> wrote in message
news:uGWGo7IYFHA.796@xxxxxxxxxxxxxxxxxxxxxxx
> Hello All:
>
> First let me thank everyone on the forum(s) for all the great (and timely)
> help!!!
>
> I am writing a help desk app in asp.net that allows people to input work
> orders for IT. I used to use data adapters and datasets until someone
> here helped me to realize the performance advantage of using data reader.
> It works great for displaying the info, but i would like to add the
> ability to pull the *number* of open and closed work orders for a
> particular user as such:
>
> SELECT * FROM workorders WHERE extension = ('extension') and STATUS =
> ('Open')
>
> SELECT * FROM workorders WHERE extension = ('extension') and STATUS =
> ('Closed')
>
> then i want the data reader to tell me how many rows were selected. I
> tried things similar to;
>
> ******************************************
> While rdr.read()
> a = a + 1
> End While
>
> labelOpenWorkOrders.text = a
> ******************************************
>
> and I also tried
>
>
> ********************************************
> while rdr.read()
> do
> a = a + 1
> loop
> end while
>
> labelOpenWorkOrders.text = a
> *******************************************
>
> It never returns the actual row count.
>
> i also tried
>
> labelOpenWorkOrders.text = rdr.recordsaffected -- but this is only for
> insert, update, delete.
>
>
> HELP!!!!
>
> Thanks
>
> Steve
>
>
>
>
>
>
.
- References:
- Using DataReader to count rows
- From: Steve Wolfie
- Using DataReader to count rows
- Prev by Date: Using DataReader to count rows
- Next by Date: Re: Using DataReader to count rows
- Previous by thread: Using DataReader to count rows
- Next by thread: Re: Using DataReader to count rows
- Index(es):
Relevant Pages
|