ADODataSet deleting from joined table

我怕爱的太早我们不能终老 提交于 2019-11-29 21:43:41

问题


I have a Delphi app where I display a list of games that have been played from a query like this:

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. 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?


回答1:


You need to use the Unique Table dynamic property

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

From the MSDN ADO Documentation

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.




回答2:


You need to set TADODataset's "Unique Table" property after opening your dataset.

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


来源:https://stackoverflow.com/questions/7981718/adodataset-deleting-from-joined-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!