本文介绍了主/细节行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用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;
这篇关于主/细节行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!