dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB6
Expertise: Intermediate
Feb 19, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Quickly create a copy of an ADO Recordset

When you want to process the data in a Recordset without affecting the actual values in the database, often the Clone method isn't what you need. For example, if you delete the records in a cloned Recordset, the original data in the database is also affected.

It seems that the only way to create a copy of a Recordset that is completely unrelated to the original Recordset is to create a disconnected Recordset that duplicates the structure and the data of the original one. However, if the original Recordset has its CursorLocation property set to adUseClient, there is a much more efficient shortcut:


Dim rsSource As New ADODB.Recordset
Dim rsFiltered As ADODB.Recordset
Dim rsSorted As ADODB.Recordset
Dim pb As New PropertyBag

' open a client-side Recordset    
rsSource.CursorLocation = adUseClient
rsSource.Open "Authors", "DSN=Pubs", adOpenStatic

' apply a filter 
rsSource.Filter = "author like 'J*'"

' create a copy of the filtered recordset
pb.WriteProperty "filtered", rsSource
Set rsFiltered = pb.ReadProperty("filtered")

' sort the recordset
rsSource.Filter = ""
rsSource.Sort = "Author"

' create a copy of the sorted recordset
pb.WriteProperty "sorted", rsSource
Set rsSorted = pb.ReadProperty("sorted")

' release the memory
Set pb = Nothing

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date