问题描述
我有2个数据表. 1与SqlServer中我表中的当前行,1与我要添加的新行.
I have 2 DataTables. 1 with the current rows in my table from SqlServer and 1 with new rows that I want to add.
我想做类似的事情:
datatable1.Merge(datatable2);
我试图弄清楚这两个表之间是否存在重复项,该重复项会添加到datatable1中还是会更新datatable1中的值?
I am trying to figure out, if duplicates between these two tables exist, will the duplicate be added to datatable1, or will it update the values in datatable1?
我需要简单地在datatable1中更新重复项,而将非重复项添加到datatable1中.
I need for duplicates to simply be updated in datatable1, and non-duplicates to be added to datatable1.
我搜索了MSDN,但我找不到真正的答案.
Iv searched MSDN and I cant really find a distinct answer.
推荐答案
从合并文档
它将更新具有相同主键的任何行.主键由 DataTable.PrimaryKey
属性
It will update any row that has the same primary key. The primary key is set by the DataTable.PrimaryKey
property
这篇关于C#-DataTable.Merge()是否添加重复项或更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!