Article ID: 195512 - View products that this article applies to.
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 recordset remains empty until it is associated with one. Therefore, it is possible to create a Recordset object at any point in a procedure, but not populate it until necessary.
This makes it possible to create a recordset and then associate it with an active command based on user input. The developer does not have to create a recordset for each possible scenario.
Another benefit is that you can close and reopen the recordset as needed without re-creating it. For example, you can close a recordset and then reopen it, as needed, using a modified command. It is less expensive in terms of performance to modify a recordset without recreating it because the application is not required to reprocess all the information that defines a recordset.
The example in the MORE INFORMATION section demonstrates setting several properties of a recordset, performing a query, reusing the recordset to perform a query on a different table, and displaying the properties, to demonstrate 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 optimistic locking. It queries the AUTHORS table in the SQL Server sample PUBS database and displays the count of returned records and several recordset properties. It then closes this recordset, reuses the recordset to perform another query on the TITLEAUTHOR table, and displays the same information described 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 of Visual Studio 6.0 or can be downloaded from the following Web address:
NOTE: Change the SERVER, UID and PWD parameters to match your SQL Server installation.
Article ID: 195512 - Last Review: February 21, 2014 - Revision: 4.2