Re: Using DataReader to count rows

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: wavread, performance due to memory allocation
    ... this technique is known as preallocation. ... Rather than forcing MATLAB ... to allocate more memory for a growing array each time through the FOR loop, ... preallocation forces MATLAB to allocate memory once before the FOR loop, ...
    (comp.soft-sys.matlab)
  • Re: How to create a list of functions depending on a parameter?
    ... argument, returning the sum between argument and index in the list, so ... Unfortunately, each function in the list fbehaves as a closure, ... comprehension loop). ... But be careful using such a technique with mutable arguments... ...
    (comp.lang.python)
  • Re: Loop through datareader after binding to repeater control
    ... data reader is read-only, forward-only. ... you need to requery database in order to loop ... use OleDbdataAdapter to fill a dataTable and loop through the ... Dim spApproverList As OleDb.OleDbDataReader ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Loop through datareader after binding to repeater control
    ... data reader is read-only, forward-only. ... you need to requery database in order to loop ... use OleDbdataAdapter to fill a dataTable and loop through the ... Dim spApproverList As OleDb.OleDbDataReader ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: stopping a loop
    ... Quote- "You can also use this technique to have a loop that runs prior to ... > animations and slide advances are timed to advance without user input. ... hide all the slides NOT in the looping section. ...
    (microsoft.public.powerpoint)