I'm using Delphi XE3 with a MySQL database. I have a SQLconnection – SQLquery – DataSetProvider – ClientDataSet arrangement. When I ApplyUpdates of a modification to the CDS, the change is affected in the database correctly but when I Refresh the CDS, the "old" values are replaced. The code I'm using is:

 CDS.IndexFieldNames:='pop0';
 CDS.first;
 for W := 1 to 5 do begin  //   display the original data
  memo2.lines.add (IntToStr(CDS['pop0']));  CDS.Next;
 end;
 memo2.lines.add('');

  CDS.first;
  CDS.Edit;                   //    modify data
  CDS['pop0']:= 3004;
  CDS.Post;
  CDS.first;
 for W := 1 to 5 do begin   //   display the modified data
  memo2.lines.add (IntToStr(CDS['pop0']));  CDS.Next;
 end;
 memo2.lines.add('');

 CDS.ApplyUpdates(0) ;
 messagedlg('Check database',mtInformation,[mbOK],0);
 CDS.refresh;

 CDS.first;
 for W := 1 to 5 do begin   //   display the updated data
  memo2.lines.add (IntToStr(CDS['pop0']));  CDS.Next;
 end;

the output in the memo is as follows:

3
4
375
597
678

4
375
597
678
986

3
4
375
597
678

I have tried to close and open the CDS as an alternative for refresh but I got the same result. Any ideas why this is happening?

有帮助吗?

解决方案

Would you tell us why the call to Refresh? TClientDataSet (CDS) usually does not require that.

Besides, was the SQLQuery open or closed when you opened the CDS? It must be closed so the DatasetProvider (DSP) will open it, retrieve all the rows and close it back.

If the DSP finds the dataset already open, it will only navigate along the records, build the record pack (named as Data) and send it to the CDS. The dataset will be left alone, whitout being closed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top