主从关系 [英] Master Detail Relationship

查看:136
本文介绍了主从关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到有关数据关系的一些问题.主表和子表由整数列关联.此列是身份"列,当调用DataAdapter的更新命令时,它会自动增加其值.当我尝试添加新行时,会出现问题.主表正常工作.但是,明细表与主表无关.例如,如果相关列的值是新的主表行是10,但明细的值是-1或-2或-3 ...

我尝试在任何新插入之后在主表上调用fill命令;然后创建明细表.但是,从性能方面考虑,不建议这样做.

有什么方法可以解决此问题.

I have seen some problem regarding to data relation. The master and child table are related by an integer column. This column is Identity column and it automatically increments its value when the update command of the DataAdapter is called. The problem occurs when I try to add a new row. The master table works normally. However the detail table is not related with the master table accordingly. For example, if the value of the relating column is the new master table row is 10 but that of the detail is -1 or -2 or -3 ...

I have tried to call the fill command on the the master table after any new insert; then create the detail table. However, Performance wise this is not recommendale.

Is there any way to work around this problem.

推荐答案

处理此问题的一种方法是在insert语句中使用OUTPUT子句.通过输出,您可以从插入的行中获取标识列的值,而无需对服务器进行额外调用.

更多信息: http://msdn.microsoft.com/en-us/library/ms177564.aspx [ ^ ]
One way to handle this is to use the OUTPUT clause in your insert statement. With output you can get the value of the identity column from the inserted row without making an extra call to the server.

More info: http://msdn.microsoft.com/en-us/library/ms177564.aspx[^]


这篇关于主从关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆