C#中怎样用LINQ语句查询出DataTable中的最大值?

tlanso 2012-08-14 12:14:41
我的价格表(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 列的最大值?

...全文
1377 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
int minUP=dt.AsEnumerable().Where(t=>t.Field<int?>("UnitPrice")!=null).(t=>t.Field<int>("UnitPrice")).Min();
tlanso 2012-08-14
  • 打赏
  • 举报
回复
追问一下,如果UnitPrice列中含有null,但是要得到该列中除null外的最小值怎么处理?
cupyonglist 2012-08-14
  • 打赏
  • 举报
回复
var query = (dt.AsEnumerable().Select(t=>t.Field<int>("SalesVolume")).Max()).Union (dt.AsEnumerable().Select(t=>t.Field<int>("UnitPrice")).Max())
q107770540 2012-08-14
  • 打赏
  • 举报
回复

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

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

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧