主/细节行为

编程入门 行业动态 更新时间:2024-10-24 18:25:49
本文介绍了主/细节行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我使用Delphi 7 + Zeos + MySQL,当我尝试发布主表时,我遇到了一个问题,详细信息数据集首先发布,在数据库中引发了一个参考完整性异常,couse details tables需要ID主表。

我可以恢复这种行为吗?我可以在细节之前坚持主表吗?

解决方案

我认为这只是 TDataSet 工作。如果您没有发布详细记录,请高手。发布强制他们到发布如果我记得正确。

所以我猜你有这样的东西:

tblMaster.Insert; tblMaster.FieldByName('foo')。Value:='foo'; tblDetail.Insert; tblDetail.FieldByName('bar')。值:='bar'; tblMaster.Post; //错误! tblDetail.Post;

你应该能够通过发布主人来解决这个问题:

tblMaster.Insert; tblMaster.FieldByName('foo')。Value:='foo'; tblMaster.Post; tblDetail.Insert; tblDetail.FieldByName('bar')。值:='bar'; tblDetail.Post;

I use Delphi 7 + Zeos + MySQL, and I got a problem when I try to post Master table, the Details datasets are posted first, raising a referencial integrity exception in data base, 'couse details tables needs the ID of the Master table.

Can I revert this behavior? Can I persist the master table before the details?

解决方案

I think it's just the way TDataSet work. If you have unposted detail records, master.Post forces them to Post if I remember correctly.

So I am guessing you have something like:

tblMaster.Insert; tblMaster.FieldByName('foo').Value := 'foo'; tblDetail.Insert; tblDetail.FieldByName('bar').Value := 'bar'; tblMaster.Post; // error! tblDetail.Post;

You should be able to work around this by posting master first:

tblMaster.Insert; tblMaster.FieldByName('foo').Value := 'foo'; tblMaster.Post; tblDetail.Insert; tblDetail.FieldByName('bar').Value := 'bar'; tblDetail.Post;

更多推荐

主/细节行为

本文发布于:2023-11-23 01:42:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619651.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:细节

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!