我在合并两个数据集时遇到约束冲突的例外 [英] I am getting exception of constraint voilation on merging two dataSets

查看:56
本文介绍了我在合并两个数据集时遇到约束冲突的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试合并具有相同模式的两个类型化的数据集DS1和DS2,并且每个表都定义了一个主键. DS2中的两个表T1,T2包含一些新行和一些与DS1对应表中的行相似的行;并且表T3之一在两个数据集中都包含完全相同的数据.当我尝试

DS1.Merge(DS2)

时,出现了异常无法启用约束.一或多个行包含违反非空,唯一或外键约束"的值.在进一步的验证中,我知道该异常是由于T1和T2中有重复的行.合并操作已将这些重复的行插入了DS1中,并且由于主键我得到了异常.另一方面,T3的所有数据与DS1和DS1中的相似. DS2合并工作良好,没有任何重复数据.
我还尝试合并每个单独的表,例如

DS1.T1.Merge(DS2.T1)

那我就没有例外.
有人可以告诉我这种例外的原因是什么吗?合并两个数据集和合并两个表有什么区别?是我需要单独合并每个表而不是合并数据集吗?

,谢谢,
Priyanka

Hi,
I am trying merge two typed DataSets DS1 and DS2 with same schema and also each table has a primary key defined. Two of the tables T1,T2 in DS2 contains some new rows and some rows similar to that in corresponding tables of DS1; and also one of the table T3 contains exactly same data in both the dataSets. When I tried

DS1.Merge(DS2)

I am getting an exception "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints". On further verification I came to know that the exception is because of duplicate rows in T1 and T2.The merge operation has inserted these duplicate rows in DS1 and because of primary key i got the exception. On the other hand T3 with all data similar in DS1 & DS2 merge worked fine without any duplicacy of data.
I also tried to merge each individual table, like

DS1.T1.Merge(DS2.T1)

then i didn't get any exception.
Can someone please tell me what can be the reason for this exception? Whats the difference when in merging two datasets and merging two tables? Is it that I need to merge each table individually rather than merging the dataSets?

Thanks,
Priyanka

推荐答案

Hello Priyanka,

感谢您的发帖!我建议将您的问题发布到MS论坛之一中,

论坛首页 > 数据平台开发论坛
> ADO.NET数据集

位于此处: http://social.msdn.microsoft.com/Forums/zh- US/adodotnetdataset/threads


这篇关于我在合并两个数据集时遇到约束冲突的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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