Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Clearing a Recordset for reuse

Reply
Thread Tools

Clearing a Recordset for reuse

 
 
+Bob+
Guest
Posts: n/a
 
      04-05-2009

I'd like to use an RS to get a total count of available records. I
would then like to reuse the RS object to get the specific record I
need (instead of creating a new RS).

What command should I use to just "clear" the RS? RS.close? Set RS=
nothing? Or is there a better way?

Thanks,
 
Reply With Quote
 
 
 
 
Daniel Crichton
Guest
Posts: n/a
 
      04-06-2009
+Bob+ wrote on Sun, 05 Apr 2009 17:32:15 -0400:


> I'd like to use an RS to get a total count of available records. I
> would then like to reuse the RS object to get the specific record I
> need (instead of creating a new RS).


> What command should I use to just "clear" the RS? RS.close? Set RS=
> nothing? Or is there a better way?


> Thanks,


Just use RS.close to close it. If you set it to Nothing then you will need
to set it again to a new object reference to use it a second time which is
wasteful on resources, although the effect may well be almost negligible
depending on your hardware and software configurations.

--
Dan


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      04-06-2009
+Bob+ wrote:
> I'd like to use an RS to get a total count of available records. I
> would then like to reuse the RS object to get the specific record I
> need (instead of creating a new RS).
>
> What command should I use to just "clear" the RS? RS.close? Set RS=
> nothing? Or is there a better way?
>

As Saniel says, RS.Close would be appropriate.
However, since it sounds as if you know which record you want to retrieve
without knowing how many are available, you might consider retrieving a
single recordset that contains both pieces of information, by using a
subquery:

select field1,...,fieldN,
(select count(*) from table where ...) as totalavailable
from table where ...

Alternatively, if your backend database supports batched commands (Jet
doesnt, SQL Server does), you can issue two sql statements that each return
records, and use NextRecordset to retrieve each resultset.

Personally, I would prefer the first approach: if the information I need can
be retrieved in a single resultset, then it really makes sense to do it that
way, avoiding unnecessary round trips to the database.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
+Bob+
Guest
Posts: n/a
 
      04-07-2009
On Mon, 6 Apr 2009 06:53:00 -0400, "Bob Barrows"
<(E-Mail Removed)> wrote:

>+Bob+ wrote:
>> I'd like to use an RS to get a total count of available records. I
>> would then like to reuse the RS object to get the specific record I
>> need (instead of creating a new RS).
>>
>> What command should I use to just "clear" the RS? RS.close? Set RS=
>> nothing? Or is there a better way?
>>

>As Saniel says, RS.Close would be appropriate.
>However, since it sounds as if you know which record you want to retrieve
>without knowing how many are available, you might consider retrieving a
>single recordset that contains both pieces of information, by using a
>subquery:
>
>select field1,...,fieldN,
>(select count(*) from table where ...) as totalavailable
>from table where ...
>
>Alternatively, if your backend database supports batched commands (Jet
>doesnt, SQL Server does), you can issue two sql statements that each return
>records, and use NextRecordset to retrieve each resultset.
>
>Personally, I would prefer the first approach: if the information I need can
>be retrieved in a single resultset, then it really makes sense to do it that
>way, avoiding unnecessary round trips to the database.


Thanks, that will do it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To reuse or not to reuse jacob navia C Programming 19 12-18-2006 07:22 AM
code reuse and design reuse sailor.gu@gmail.com C Programming 16 02-12-2006 09:09 PM
Reuse paramter list and reuse connection tshad ASP .Net 5 05-17-2005 12:33 AM
To reuse or not to reuse.... Hylander Java 0 02-26-2004 12:00 AM
reuse repeater with new recordset Bob ASP .Net 0 07-07-2003 07:03 PM



Advertisments