This article was previously published under Q195512
This article has been archived. It is offered "as is" and will no longer be updated.
When you create a Recordset object without an active command, the recordsetremains empty until it is associated with one. Therefore, it is possible tocreate a Recordset object at any point in a procedure, but not populate ituntil necessary.
This makes it possible to create a recordset and then associate it with anactive command based on user input. The developer does not have to create arecordset for each possible scenario.
Another benefit is that you can close and reopen the recordset as neededwithout re-creating it. For example, you can close a recordset and thenreopen it, as needed, using a modified command. It is less expensive interms of performance to modify a recordset without recreating it becausethe application is not required to reprocess all the information thatdefines a recordset.
The example in the MORE INFORMATION section demonstrates setting severalproperties of a recordset, performing a query, reusing the recordset toperform a query on a different table, and displaying the properties, todemonstrate that the Recordset properties are not altered by reuse.
This example instantiates a Recordset object using the SQL Server driver,sets it to use server-side cursors, a dynamic cursortype, and optimisticlocking. It queries the AUTHORS table in the SQL Server sample PUBSdatabase and displays the count of returned records and several recordsetproperties. It then closes this recordset, reuses the recordset to performanother query on the TITLEAUTHOR table, and displays the same informationdescribed in the previous sentence.
To use this example, you must have Microsoft Data Access Components (MDAC)version 2.x or later installed, which is included in the data components ofVisual Studio 6.0 or can be downloaded from the following Web address: