Clearing a Recordset for reuse

Discussion in 'ASP General' started by +Bob+, Apr 5, 2009.

  1. +Bob+

    +Bob+ Guest

    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,
     
    +Bob+, Apr 5, 2009
    #1
    1. Advertising

  2. +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
     
    Daniel Crichton, Apr 6, 2009
    #2
    1. Advertising

  3. +Bob+

    Bob Barrows Guest

    +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"
     
    Bob Barrows, Apr 6, 2009
    #3
  4. +Bob+

    +Bob+ Guest

    On Mon, 6 Apr 2009 06:53:00 -0400, "Bob Barrows"
    <> 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.
     
    +Bob+, Apr 7, 2009
    #4
    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. tshad
    Replies:
    5
    Views:
    539
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    424
    Hylander
    Feb 26, 2004
  3. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,032
    Malcolm
    Feb 12, 2006
  4. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    533
    Dave Thompson
    Dec 18, 2006
  5. Intransition

    Clearing TOPLEVEL_BINDING for reuse

    Intransition, Jun 5, 2010, in forum: Ruby
    Replies:
    2
    Views:
    96
    Intransition
    Jun 6, 2010
Loading...

Share This Page