Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to append data to ClientDataSet

Status
Not open for further replies.

hstijnen

Programmer
Nov 13, 2002
172
NL
Hi,

I have a clientDataSet in the following structure:
ClientDataSet -> DataSetProvider -> TQuery

I have opened the ClientDataSet and have records in it. Now I want to append other records to the dataset by specifying a command in the CommandText property.

When I call ClientDataSet->Open() I loose the records I already have. What must I do to append the new records to the existing set?

Another question: How can I remove retrieved records from the ClientDataSet? NB: not delete them from the database, but remove "as if they were not retrieved"

Thanks

Henk Stijnen
 
I've not used TQuery so I can't say exactly what is happening. According to my notes, there are five steps to using query at design time:
1[tab]Place a query component from the Data Access tab of the Component palette in a data module, and set its Name property appropriately for your application.

2[tab]Set the DatabaseName property of the component to the name of the database to query. DatabaseName can be a BDE alias, an explicit directory path (for local tables), or the value from the DatabaseName property of a TDatabase component in the application.

3[tab]Specify an SQL statement in the SQL property of the component, and optionally specify any parameters for the statement in the Params property. For more information, see "Specifying the SQL property" at design time in your help file.

4[tab]If the query data is to be used with visual data controls, place a data source component from the Data Access tab of the Component palette in the data module, and set its DataSet property to the name of the query component. The data source component is used to return the results of the query (called a result set) from the query to data-aware components for display. Connect data-aware components to the data source using their DataSource and DataField properties.

5[tab]Activate the query component. For queries that return a result set, use the Active property or the Open method. For queries that only perform an action on a table and return no result set, use the ExecSQL method.

To execute a query for the first time at runtime, follow these steps:

1[tab]Close the query component.

2[tab]Provide an SQL statement in the SQL property if you did not set the SQL property at design time, or if you want to change the SQL statement already provided. To use the design-time statement as is, skip this step. For more information about setting the SQL property, see "Specifying the SQL statement to execute" in you help files

3[tab]Set parameters and parameter values in the Params property either directly or by using the ParamByName method. If a query does not contain parameters, or the parameters set at design time are unchanged, skip this step. For more information about setting parameters, see "Setting parameters" in you help files. This may be where your troubles lie.

4[tab]Call Prepare to initialize the BDE and bind parameter values into the query. Calling Prepare is optional, though highly recommended. For more information about preparing a query, see "Preparing a query" in your help files.

5[tab]Call Open for queries that return a result set, or call ExecSQL for queries that do not return a result set. For more information about opening and executing a query see "Executing a query" in you help files. James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Thanks for your answer. Alas it is not the answer to my question. The question is when I have "Opened" the query component, I have a set of records retrieved from the database. Now I want to extend the existing set, while retaining that set, with another set of records.

Note: when you open a TQuery, you have a connection with the dtabase (logged in user) until the query is closed.

When you have a clientDataSet in the following structure:
ClientDataSet -> DataSetProvider -> TQuery
and you open the ClientDataSet, the system opens the TQuery, retrieves the data and provides that via the DataSetProvider to your local ClientDataSet. Then the TQuery is closed (if the right option is set) and there is no logged in user. In that way I have a 10 user Server License for about 70 users.

Back to my question: I want to extend the local ClientDataSet with more records.

Regards

Henk Stijnen

 
AFAIK, you have to close the query, rerun it, then reopen it. Like I say, I've never used the query. I've use BDE and client sets, and I am now experimenting with Flash Filer as a BDE replacement. If I get more time I'll see what I can come up with.

In the mean time, maybe someone here has used TQuery and can tell you more. James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top