插入父子关系

编程入门 行业动态 更新时间:2024-10-26 08:27:26
本文介绍了插入父子关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我在父子表中有一对多的关系。我想在单个事务中插入记录是两个表。如果因为任何原因没有插入子表记录,那么父记录也需要回滚。 我们如何使用asp在业务层实现这一点。 /> Thanx&Regards Santosh

Hi All, I have one to many relation in parent child table. I want to insert records is both table in single transaction. If because of any reason child table records not get inserted then parent record also need to rollback. How would we achieve this in business layer using asp. Thanx & Regards Santosh

推荐答案

最好的方法是要将它创建为存储过程,但无论您是这样做还是内联代码,您真正需要做的是创建一个事务,您可以在两个插入成功后提交,或者如果失败则返回。 你究竟是怎么做的,取决于内联或SP,以及你选择的语言,但对于SP,请参见此处:technet.microsoft/en-us/library/ms188929.aspx [ ^ ]和C#见这里: msdn.microsoft/en-us/library/system.data.sqlclient.sqltransaction.aspx [ ^ ] The best way to do this is to create it as a stored procedure, but whether you do that or inline the code what you really need to do is create a Transaction, which you either Commit after both inserts have succeeded, or Rollback if either fails. Exactly how you do that will depend on in-line or SP, and the language you choose, but for SP see here: technet.microsoft/en-us/library/ms188929.aspx[^] and for C# see here: msdn.microsoft/en-us/library/system.data.sqlclient.sqltransaction.aspx[^]

更多推荐

插入父子关系

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

发布评论

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

>www.elefans.com

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