views:

498

answers:

3

My question is very simple. I have a TClientDataSet that is linked to a TADOQuery via a TDataSetProvider. I can put data into the TClientDataSet from the TADOQuery, but how do I get data from the TClientDataSet back into the TADOQuery?

Data is automatically transferred from the TADOQuery to the TClientDataSet when I run a query and then set the TClientDataSet's Active property to True, but if I deactivate the TADOQuery and then activate it again, how can I get the data back from the TClientDataSet?

I am running the same query on several databases and using the TClientDataSet to concatenate the results. This is working fine. My problem now is that I need to get the concatenated result set back from the TClientDataSet into the TADOQuery so that I can use the TADOQuery's SaveToFile procedure (for compatibility reasons). How can I do this?

A: 

I don't do TADOQuery as I use dbExpress, but I imagine that one needs to use the same technique. After you have posted your changes to TClientDataSet, call 'ApplyUpdates (0)', which transfers the data from the clientdataset to its provider.

No'am Newman
Unfortunately, that doesn't work.I tried calling ApplyUpdates, which didn't give me an error, but didn't update the TADOQuery (same record cound as before the update). I guessed that it was just updating the DataSetProvider (between the ClientDataSet and ADOQuery) so I tried calling ApplyUpdates on that as well. This gave me an error ("Missing Connection or ConnectionString"). I then set the ADOQuery's connection string to "Provider=MSDAOSP.1;Persist Security Info=False" and tried again, but then got another error ("Object or provider is not capable of performing requested operation")
Jeedee
A: 

You could always write the dataset back out to a temp table and then query it. Ouch!!

Ken Lange
Actually, that's a good idea. A lot of reporting applications do that and it's considered a good approach.
Pmax
A: 

I've just about finished looking into this. My application allows the user to generate reports by querying their databases. I can get this to work and it is very efficient for small result sets - however, as this is a reporting application, and it's entirely possible that hundreds of thousands of records can be returned, using a ClientDataSet gives massive performance problems. Once you get above around 50,000 records (reasonable, given the customer base), processing starts to increase exponentially, so this is now basically moot.

Jeedee
Have you tried it with MidasSpeedFix and FastMM4? http://andy.jgknet.de/blog/?p=437Also, if you don't need to write changes back to the database then turning the ChangeLog off helps performance quite considerably.
RichardS
Yep. Tried that. Unless I'm doing something wrong, it didn't make that much difference to the processing time. At the moment, the TADOQuery can run a query that returns 450,000 records and save it to file in under 4 minutes. The TClientDataSet processing went well over 30 minutes, at which point I had to shut down the test application. To get the results that I need, I'm keeping my existing processing and parsing the XML document (ADOQuery.SaveToFile) and manually concatenating the data.
Jeedee