本文介绍了TClientDataSet错误:“缺少数据提供者或数据包"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在用Delphi中的代码创建一个TClientDataSet和TDataSetProvider,并从TUniQuery(Devart UniDAC)加载数据.设置数据集提供程序和clientdataset的属性后,我尝试打开clientdataset并获取运行时异常:缺少数据提供程序或数据包".

I'm creating a TClientDataSet and TDataSetProvider in code in Delp 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.

这是我的代码:

//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));

推荐答案

如果DatasetProvider没有所有者,则ClientDataSet无法获取对该提供程序的引用.

If DatasetProvider has no owner, ClientDataSet can not obtain a reference to the provider.

所以使用

...Create(Self);

代替

...Create(nil);

这篇关于TClientDataSet错误:“缺少数据提供者或数据包"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:17