我们可以使用LINQ过滤数据表吗? [英] Can we filter Datatable with LINQ?

查看:58
本文介绍了我们可以使用LINQ过滤数据表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的数据表中充满了数据. 填充数据后,我们可以再次使用linq在数据表上添加一些条件以提取数据.

Suppose my datatable is filled with data. After filling data can we again put some condition on datatable with linq to extract data.

假设我的数据表有10条员工记录. 因此,我们可以使用linq查询仅提取薪水大于5000的那些雇员. 我知道我们可以实现它.您如何使用linq做到这一点?

Suppose my datatable has 10 employee record. So can we extract only those employee whose salary is greater than 5000 with linq query. I know that we can achieve it datatable.select(). How can you achieve this with linq?

推荐答案

您可以获取一组经过过滤的行,是的:

You can get a filtered set of rows, yes:

var query = table.AsEnumerable()
                 .Where(row => row.Field<decimal>("salary") > 5000m);

这在 DataTableExtensions DataRowExtensions .

这篇关于我们可以使用LINQ过滤数据表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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