Assigning Data Directly
Go Up to Copying Data from Another Dataset
You can use the client dataset's Data property to assign data to a client dataset from another dataset. Data is a data packet in the form of an OleVariant. A data packet can come from another client dataset or from any other dataset by using a provider. Once a data packet is assigned to Data, its contents are displayed automatically in data-aware controls connected to the client dataset by a data source component.
When you open a client dataset that represents server data or that uses an external provider component, data packets are automatically assigned to Data.
When your client dataset does not use a provider, you can copy the data from another client dataset as follows:
ClientDataSet1.Data := ClientDataSet2.Data;
ClientDataSet1->Data = ClientDataSet2->Data;
Note: When you copy the Data property of another client dataset, you copy the change log as well, but the copy does not reflect any filters or ranges that have been applied. To include filters or ranges, you must clone the source dataset's cursor instead.
If you are copying from a dataset other than a client dataset, you can create a dataset provider component, link it to the source dataset, and then copy its data:
TempProvider := TDataSetProvider.Create(Form1); TempProvider.DataSet := SourceDataSet; ClientDataSet1.Data := TempProvider.Data; TempProvider.Free;
TempProvider = new TDataSetProvider(Form1); TempProvider->DataSet = SourceDataSet; ClientDataSet1->Data = TempProvider->Data; delete TempProvider;
Note: When you assign directly to the Data property, the new data packet is not merged into the existing data. Instead, all previous data is replaced.
If you want to merge changes from another dataset, rather than copying its data, you must use a provider component. Create a dataset provider as in the previous example, but attach it to the destination dataset and instead of copying the data property, use the ApplyUpdates method:
TempProvider := TDataSetProvider.Create(Form1); TempProvider.DataSet := ClientDataSet1; TempProvider.ApplyUpdates(SourceDataSet.Delta, -1, ErrCount); TempProvider.Free;
TempProvider = new TDataSetProvider(Form1); TempProvider->DataSet = ClientDataSet1; TempProvider->ApplyUpdates(SourceDataSet->Delta, -1, ErrCount); delete TempProvider;