I want save ClientDataSet to file and then open this file in AdoQuery (AdoQuery.LoadFromFile()). Is it possible?
Or how can I save dataset to pfADTG file format?
Best regards
Pawel
I want save ClientDataSet to file and then open this file in AdoQuery (AdoQuery.LoadFromFile()). Is it possible?
No. The file formats used by TClientDataSet and the TCustomAdoDataSet descendants like TAdoQuery are not compatible with one another, either in their binary versions or their XML ones. I suppose you could try using Delphi's TXmlTransform to convert a saved CDS file to Ado format, but I've never done this myself.
Or how can I save dataset to pfADTG file format?
If by "dataset" you mean a TClientDataSet, you cannot do this directly. The best you can do is to do a field-by-field, row-by-row copy from the CDS to the AdoQuery and then call SaveToFile on the AdoQuery.
Update: In an edit to this answer, which I'm afraid I had to reject, you asked what to do if your AdoDataSet is empty and doesn't have a connection string; Well, to can certainly use a TAdoDataSet to store data locally using SaveToFile and LoadFromFile. Below is a minimalist project which creates and populates a ClientDataSet, then copies its structure and data to an AdoDataSet.
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
// Note: ClientDataSet1 has had two FieldDefs created in the IDE,
// an ID integer field and an AName string field with a size of 20
// Create and populate ClientDataSet1
ClientDataSet1.CreateDataSet;
ClientDataSet1.InsertRecord([1, 'Name1']);
ClientDataSet1.InsertRecord([2, 'Name2']);
// Copy ClientDataSet1's FieldDefs to AdoDataSet1
AdoDataSet1.FieldDefs.Assign(ClientDataSet1.FieldDefs);
// Now, copy the data fielf-by-field, row-by-row
AdoDataSet1.CreateDataSet;
try
ClientDataSet1.DisableControls;
AdoDataSet1.DisableControls;
ClientDataSet1.First;
while not ClientDataSet1.Eof do begin
AdoDataSet1.Insert;
for i := 0 to ClientDataSet1.FieldCount - 1 do begin
AdoDataSet1.Fields[i].Value := ClientDataSet1.Fields[i].Value;
end;
AdoDataSet1.Post;
ClientDataSet1.Next;
end;
// Save Ado data to file, beware of path used!
AdoDataSet1.SaveToFile(ExtractFilePath(Application.ExeName) + 'AdoData', pfADTG);
finally
AdoDataSet1.EnableControls;
ClientDataSet1.EnableControls;
end;
end;