4

I would like to know how I can save a query in memory to display in DBgrid,

my current application is using :

TZConnection > TZquery > DataSource > DBgrid

works fine but the problem here is, after a call ZConnection.disconnect the dbgrid is cleaned

i want to disconnect TZConnection immediately after finish the query because most MySQL databases have an limited numbers of user connected simultaneously.

Rebelss
  • 364
  • 1
  • 5
  • 15
  • I'd copy the whole data to a TClientDataSet or TkbmMemTable(?) but since you kill the connection, why not display data in a TListView or TVirtualStringTree? –  Dec 19 '12 at 06:21
  • Can you put some examples to Copy whole data to the ClientDataSet, i try that but with no sucess. – Rebelss Dec 19 '12 at 06:23
  • @Rebless it's a two stage operation(or 1 if you setup the client data set in design time), the two stage is: 1) for each "field" in your query, create a field in "client data set", 2) for each *record* in query, copy content to "client data set", really easy and straight forward, it will be a very nice exercise, have fun! –  Dec 19 '12 at 06:26

1 Answers1

4

Use the TDataSetProvider to transfer your Query data into the ClientDataSet. That component does everything for you.

Put the following components on your DataModule, and link them accordingly:

TZQuery <- TDataSetProvider <- TClientDataSet <- TDataSource

TDataSource.DataSet := TClientDataSet;
TCLientDataSet.ProviderName := TDataSetProvider;
TDataSetProvider.DataSet := TZQuery;

After that, just call the TClientDataSet.Open method, and the data are transfered automaticaly into the TClientDataSet. With TClientDataSet.ApplyUpdates, you can push back the data into your database.

I use that technic with firebird (TIBQuery).

Here are some information about ClientDataSets:
A ClientDataSet in Every Database Application
Delphi In Depth: ClientDataSet book
Building Applications With ClientDataSet and InterBase Express

markus_ja
  • 2,931
  • 2
  • 28
  • 36
  • Thx for your help but, that doesn't work for me, TZQuery > TDataSetProvider - ok, i can set the TDataSetProvider property "DataSet" to TZQuery but now there's no link between TDataSetProvider and TClientDataSet can you wrote a little example for me ? – Rebelss Dec 19 '12 at 12:33
  • See edit above. You can connect them in the ObjectInspector at design time. – markus_ja Dec 19 '12 at 12:58