简体   繁体   English

从连接表中删除ADODataSet

[英]ADODataSet deleting from joined table

I have a Delphi app where I display a list of games that have been played from a query like this: 我有一个Delphi应用程序,我在其中显示从这样的查询中播放的游戏列表:

select  g.*, gt.id, gt.descr 
from GAMES g 
inner join game_types gt on gt.id = g.game_type
order by game_date DESC

When I click the delete button in the DBNavigator, the joined record from the game_types table is also deleted. 当我单击DBNavigator中的删除按钮时,也会删除game_types表中的联接记录。 That's a problem because many other games can be of the same type. 这是一个问题,因为许多其他游戏可能属于同一类型。

What do I need to do to make it so that only the game is deleted but not the game type? 我需要做些什么才能只删除游戏但不删除游戏类型?

You need to use the Unique Table dynamic property 您需要使用Unique Table动态属性

ADOQuery1.Properties['Unique Table'].Value := 'GAMES';

From the MSDN ADO Documentation 来自MSDN ADO文档

If the Unique Table dynamic property is set, and the Recordset is the result of executing a JOIN operation on multiple tables, then the Delete method will only delete rows from the table named in the Unique Table property. 如果设置了Unique Table动态属性,并且Recordset是对多个表执行JOIN操作的结果,则Delete方法将仅删除Unique Table属性中指定的表中的行。

打开数据集后,需要设置TADODataset的“唯一表”属性。

ADODataset.Properties['Unique Table'].Value := 'GAMES';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM