如何在DataSet中过滤特定数据 [英] how to filter a specific data in DataSet

查看:246
本文介绍了如何在DataSet中过滤特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个数据集,它们包含以下内容:
第一个数据集(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

推荐答案

一种方法是使用LINQ.要查询数据,代码可能类似于:
One way to do this is to use LINQ. To query the data, the code could be something like:
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.


您实际上可以直接在id的DataSet中进行过滤.
此处阅读更多信息 [
You can actually directly filter within the DataSet on the id.
read more about this here[^].


这篇关于如何在DataSet中过滤特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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