问题描述
我有2个数据表,我想创建第三个数据表的数据表contais和1之间的差异数据表2。
I have 2 DataTable and I want to create a third DataTable that contais the difference between DataTable 1 and DataTable 2.
例如,DataTable1具有原始数据和数据表2仅仅是一个拷贝,象一个复制。但是,当你在DataTable1插入一个新行,该DataTable2刚刚插入同一行。 DataTable1和DataTable2之间Nowaday我的code做一个比较,如果不等于(1行或更多插入),DataTable2记录从DataTable1所有数据一次。
For example, DataTable1 has the original data, and the DataTable 2 is just a copy, like a replication. But when you insert a new row in DataTable1, the DataTable2 has just insert the same row. Nowaday my code do a compare between DataTable1 and DataTable2, if not equals (1 row or more was inserted), DataTable2 record all data from DataTable1 again.
我怎样才能做一个选择命令,即做到这一点的区别,并在第三个数据表中记录这些DATAS?
How can I do a select command, that do this difference and record those datas in a third DataTable ?
推荐答案
我会考虑,有两列,以确定该表(COL1,COL2)
I will consider that there are two columns to identify the tables(col1,col2)
var rowsOnlyInDt1 = dt1.AsEnumerable().Where(r => !dt2.AsEnumerable()
.Any(r2 => r["col1"].Trim().ToLower() == r2["col1"].Trim().ToLower() && r["col2"].Trim().ToLower() == r2["col2"].Trim().ToLower()));
DataTable result = rowsOnlyInDt1.CopyToDataTable();//The third table
这篇关于差之2的DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!