General discussion


Prepared Statements to a DB

By mpalazzo ·
I'm trying to use a prepared command object (using ADO) to open a recordset. My question is, what order do I do things to ensure I'm utilizing the benefits of a prepared SQL statment. I pass my prepared SQL statment via the command object (.prepared= true) to the open recordset method. Great, I get the expected results back. I want to create a loop opening new records each time by changing my parameter. Do I close the rs, change my parameter in the command object, and reopen the same rs with the modified command object? Does closing the rs destroy the command object? What's the proper order to do things to ensure I maximize the time savings of creating a prepared SQL statement?


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Prepared Statements

by AlterEgo2 In reply to Prepared Statements to a ...

1) Your recordset (rs) and command (cmd) objects will be two separate objects. Closing and setting the rs object to nothing will not destroy the cmd object.

2) Whether you should be closing them in between each call depends on what the application is for (ie.frequency of ADO requests). Remember that there is an overhead associated with instantiating and destroying objects as well as keeping a recordset open.

If the request frequency is low and your using the same rs more than once in a page (I'm assuming that this is an ASP page) then you might consider using the getrows() method which will put the results into an array then you close your ADO objects immediatley but still use your rs data.

If the request frequency is high then keep the rs and cmd object open until such time as they are no longer needed.

It would help if you gave a little more information about the application usage.

Related Discussions

Related Forums