问题描述
我有两个数据集,它们包含以下内容:
第一个数据集(ds1)包含一个表,该表包含两列(ID和计数器)
第二个数据集(ds2)包含与第一个数据集完全相同的内容,但当然具有不同的数据.
因此,我想选择达到此条件的数据:
Hi,
I have two datasets, they consist of the following:
the first dataset (ds1) contains one table which contains two columns (ID and counter)
the second dataset (ds2) contains exactly like the first dataset but of course with different data.
So I want to choose the data that achieves this condition:
ds1.tables[0].Columns["ID"]=ds2.tables[0].Columns["ID"]
然后将新数据放入新数据集中
预先谢谢您.
and then put the new data in new dataset
thank you in advance
推荐答案
var result = from row1 in ds1.tables[0].AsEnumerable()
join row2 in ds2.tables[0].AsEnumerable()
on row1.Field<decimal>("ID")
equals row2.Field<decimal>("ID")
select row1;
示例中的select部分仅选择整个row1,但您应该对其进行修改以获取所需的结果.
查询完成后,您可以使用CopyToDataTable
方法将数据添加到新表中.
The select portion in the example selects only the row1 in whole but you should modify it to fetch the desired results.
When the query is finished, you can use CopyToDataTable
method to add the data into a new table.
这篇关于如何在DataSet中过滤特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!