无法找到记录,没有指定键

发布于 2025-01-22 18:05:24 字数 1039 浏览 0 评论 0原文

我在Delphi应用程序中遇到了这个臭名昭著的错误。 在我的adodataset中,我将命令类型设置为cmdtext,然后将命令文字设置为 select *从production.details

对DBGRID进行记录更改时,它会引发“无法找到记录,未指定键”的错误。 在我的客户端DataSet下,我将各个字段设置为[Pfinwhere,pfinupdate,pfinkey],所有其他字段[pfinwhere,pfinupdate]

一些人都提到它是Adodataset的提供商标志,需要更改的提供商标志,因为那是查询的起源。我尝试了以下 adodataset.fields [0] .providerflags:= [Pfinkey,pfinupdate,pfinwhere]; 它会从bounds 中列出列表索引的其他

错误

if mySQLDataModule.dieDetailClientDataSet.ChangeCount > 0 then
  begin
    dieDetailClientDataSet.FieldByName('die_no').ProviderFlags := [pfInWhere, pfInUpdate, pfInKey];
    dieDetailClientDataSet.FieldByName('comment').ProviderFlags := [pfInWhere, pfInUpdate];

   dieDetailADODataSet.Fields[0].ProviderFlags := [pfInKey, pfInUpdate, pfInWhere];
   dieDetailClientDataSet.ApplyUpdates(0);
  end;

但是,当我执行此操作时, 与字段[0]中指定的相同。在CD中,我已经在设计人员模式下设置了ProviderFlags。是因为我读到的是,它必须在adodataset中设置为我的查询的设置,因此我必须在此处手动设置它,因此必须将其设置在Adodataset中。因为我的所有字段都在CD中设置(因为也有计算的字段)用于显示数据它在代码中。

I am coming across this infamous error in my Delphi application.
In my ADODataSet, I have set my CommandType to cmdText, and then set CommandText to
SELECT * FROM production.details

When I do a record change on my DBGrid, it throws the error of "Unable to find record, no key specified".
Under my ClientDataSet, I have set the various fields to have the Provider Flags of [pfInWhere, pfInUpdate, pfInKey], all other fields [pfInWhere, pfInUpdate]

A few people mention that it is the Provider Flags of the ADODataSet that need to be changed, since that is where the query originates. I tried this by the following
ADODataSet.Fields[0].ProviderFlags := [pfInKey, pfInUpdate, pfInWhere];
However, when I do this it throws a different error of List index out of bounds

Eventually I have all this in my DataSourceDataChange procedure:

if mySQLDataModule.dieDetailClientDataSet.ChangeCount > 0 then
  begin
    dieDetailClientDataSet.FieldByName('die_no').ProviderFlags := [pfInWhere, pfInUpdate, pfInKey];
    dieDetailClientDataSet.FieldByName('comment').ProviderFlags := [pfInWhere, pfInUpdate];

   dieDetailADODataSet.Fields[0].ProviderFlags := [pfInKey, pfInUpdate, pfInWhere];
   dieDetailClientDataSet.ApplyUpdates(0);
  end;

More details as requested : this is a MySQL database, the primary key is the same as what is specified in Fields[0]. In the CDS I have already set the ProviderFlags in the Designer Mode. It was because it wasn't working as expected that I read that it has to instead be set in the AdoDataSet as that is where my query has been set, hence me setting it manually here. Because all my fields are set up in the CDS (as there are also calculated fields) for my DBGrid that displays the data, I didn't redo all my fields in the AdoDataSet so there wasn't a designer option there, hence me doing it in code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文