如何仅合并缺少的行

时间:2011-09-13 13:23:29

标签: c# .net ado.net

我有这段代码。

但是我在合并行中遇到了异常:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

我想要一个简单的方法,它只合并缺少的行,如果有已经存在的行,则不应该尝试复制它们

由于

// Init
UC010_WizardStepBusinessParkDataSet dataSet = new UC010_WizardStepBusinessParkDataSet();
View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkData vwBusPark = new View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkData();
View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkPortfolioManagerData vwBusParkPortfolioMngr = new View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkPortfolioManagerData();

vwBusPark.Where.BusinessParkID.Value = businessParkID;
vwBusParkPortfolioMngr.Where.BusinessParkID.Value = businessParkID;

if (vwBusPark.Query.Load())
    dataSet.BusinessPark.Merge(vwBusPark.toDataTable(), true, System.Data.MissingSchemaAction.Ignore);

1 个答案:

答案 0 :(得分:2)

尝试与

合并
vwBusPark.Except(dataSet.BusinessPark, DataRowComparer<YourRow>.Default)