无法找到记录,没有指定键
我在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 toSELECT * 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 followingADODataSet.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论