ClientDataSet modify, delete, add data and Delta properties

When used in Post ClientDataSet submit data changes, in fact, it has not been updated to the back-end database, but submitted to the management of the data buffer by DataSnap. When the ClientDataSet.ApplyUpDates (MaxErrors: integer) method is updated in the database. ApplyUpDates method of updating only modified data, attribute data on ClientDataSet.Delta. Data call AppplyUpDates update to the database at the same time in the Delta will be cleared, pay attention to the last box. The following data can be modified, or delete operation, and view the data of Delta.

Renderings:

**************************************************************************************

To do:

**************************************************************************************

Connection DBGrid1:

DBGrid1.DataSource->DataSource1.DataSet->ClientDataSet1.ProviderName->DataSetProvider1.DataSet->

SQLDataset1.SQLConnection-> SQLConnection1 specific database (oracle here is connected in the EMP table);

SQLDataSet1.CommandText:=SELECT * FROM EMP;ClientDataSet1.Active:=true;

DBNavigator1.DataSource->DataSource1;

Connection DBGrid2:

DBGrid2.DataSource->DataSource2.DataSet->ClientDataSet2;

The use of controls put in more than a blank project, according to the above settings connected control.

**************************************************************************************

Related CODE:

**************************************************************************************

Procedure TForm3.Button1Click (Sender: TObject);
 the begin 
  // delete and add data does not trigger AfterPost event, manual assignment 
  // data Delta ClientDataSet1 to ClientDataSet2 in the Data property, let DBGrid2 display processing data 
  ClientDataSet2.Data : = ClientDataSet1.Delta; 
  StatusBar1.Panels [ 0 ] .Text: = the format ( ' of Delta data count:% D ' , 
    [ClientDataSet2.RecordCount]); 
End ; 

Procedure TForm3.Button2Click (Sender: TObject);
 the begin 
    // the commit changes to the database data, 0 indicates no error occurs 
    ClientDataSet1.ApplyUpdates ( 0 ); 
    ClientDataSet2.Data: = ClientDataSet1.Delta;
End ; 

Procedure TForm3.ClientDataSet1AfterPost (the DataSet: on TDataSet);
 the begin 
  // the data Delta ClientDataSet1 to ClientDataSet2 in the Data attribute, so DBGrid2 display processing data 
  ClientDataSet2.Data: = ClientDataSet1.Delta; 
  StatusBar1.Panels [ 0 ] .Text: = the format ( ' of Delta data count:% D ' , 
    [ClientDataSet2.RecordCount]); 
End ;

 

Guess you like

Origin www.cnblogs.com/jijm123/p/11468402.html