Вопрос

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.

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top