Pregunta

Here is what I'm trying to accomplish:

  1. Retrieve 1 record from the database through TSQLDataset's CommandText: SELECT * FROM myTable WHERE ID = 1
  2. Use TClientDataset to modify the record. (1 pending update)
  3. Retrieve next record. SELECT * FROM myTable WHERE ID = 2
  4. Modify the record. (now 2 pending updates)
  5. Finally, send the 2 pending updates back to the database through ApplyUpdates function.

When I do step 3 I got "Must apply updates before refreshing data."

How can I refresh a TClientDataSet without applying pending updates?

¿Fue útil?

Solución

You can append data packets manually to your DataSet calling the AppendData method.

In an application where the provider is in the same application with the ClientDataSet you can code something like this:

begin
  ConfigureProviderToGetRecordWithID(1);
  //make the ClientDataSet fetch this single record and not hit the EOF.
  ClientDataSet1.PacketRecords := 1; 
  ClientDataSet1.Open;
  ClientDataSet1.Edit;
  ModifyFirstRecord;
  ClientDataSet1.Post;
  ConfigureProviderToGetRecordWithID(2);
  ClientDataSet1.AppendData(DataSetProvider1.Data, False); 
  //now you have two records in your DataSet without losing the delta.
end; 

This is kind of pseudo-code, but shows the general technique you could use.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top