RAD Studio |  |

Assigning Data Directly
See Also
Collapse All

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:

Copy Code

    ClientDataSet1.Data := ClientDataSet2.Data;

Copy Code

    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:
Copy Code

    TempProvider := TDataSetProvider.Create(Form1);
    TempProvider.DataSet := SourceDataSet;
    ClientDataSet1.Data := TempProvider.Data;
    TempProvider.Free;

Copy Code

    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:
Copy Code

    TempProvider := TDataSetProvider.Create(Form1);
    TempProvider.DataSet := ClientDataSet1;
    TempProvider.ApplyUpdates(SourceDataSet.Delta, -1, ErrCount);
    TempProvider.Free;

Copy Code

    TempProvider = new TDataSetProvider(Form1);
    TempProvider->DataSet = ClientDataSet1;
    TempProvider->ApplyUpdates(SourceDataSet->Delta, -1, ErrCount);
    delete TempProvider;

See Also

Cloning a Client Dataset Cursor

Editing Data

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!