问题
I'm creating a TClientDataSet and TDataSetProvider in code in Delphi, and loading the data from a TUniQuery (Devart UniDAC). After setting the properties for the dataset provider and the clientdataset, I try to open the clientdataset and get the runtime exception: "Missing data provider or data packet".
I'm not sure why its happening and would be glad if anyone could point out what exactly is wrong.
This is my code:
//uq is a TUniQuery correctly set to an active TUniConnection
cdsFirstNames := TClientDataSet.Create(nil);
dspFirstNames := TDataSetProvider.Create(nil);
try
uq.SQL.Text := 'SELECT * FROM firstnames;';
uq.Prepared := True;
// uq.Open;
dspFirstNames.Name := 'dspFirstNames';
dspFirstNames.DataSet := uq;
cdsFirstNames.ProviderName := 'dspFirstNames';
cdsFirstNames.Open; // <--- Exception occurs here!
uq.Close;
showmessage(IntToStr(cdsFirstNames.RecordCount));
回答1:
If DatasetProvider has no owner, ClientDataSet can not obtain a reference to the provider.
So use
...Create(Self);
instead of
...Create(nil);
来源:https://stackoverflow.com/questions/29987104/tclientdataset-error-missing-data-provider-or-data-packet