读书人

C#中怎样用LINQ语句查询出DataTable中

发布时间: 2013-01-26 13:47:04 作者: rapoo

C#中怎样用LINQ语句查询出DataTable中的最大值?
我的价格表(PriceTable)已经在数据库中查询到了数据,其内容为:

id SalesVolume UnitPrice

1 5 7.9

2 8 4.3

3 4 5.8

4 10 12.1

5 12 3.5

6 6 14

7 9 7

8 11 8.8

9 3 10.5

10 8 3.9



请教各位高手能否使用一个LINQ语句查询出PriceTable表的SalesVolume和UnitPrice 列的最大值?


[解决办法]


int maxSV=dt.AsEnumerable().Select(t=>t.Field<int>("SalesVolume")).Max();

int maxUP=dt.AsEnumerable().Select(t=>t.Field<int>("UnitPrice")).Max();

[解决办法]
var query = (dt.AsEnumerable().Select(t=>t.Field<int>("SalesVolume")).Max()).Union (dt.AsEnumerable().Select(t=>t.Field<int>("UnitPrice")).Max())
[解决办法]
int minUP=dt.AsEnumerable().Where(t=>t.Field<int?>("UnitPrice")!=null).(t=>t.Field<int>("UnitPrice")).Min();

读书人网 >.NET

热点推荐