4
votes

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.

1
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? - user497849
Can you put some examples to Copy whole data to the ClientDataSet, i try that but with no sucess. - Rebelss
@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! - user497849

1 Answers

4
votes

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