如何在Datatable中选择语句c# [英] How to Select statement in Datatable c#

查看:97
本文介绍了如何在Datatable中选择语句c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何选择数据表列中的最大值,还包括c#中的where语句。



谢谢,

Sivasankaran G

解决方案

 DateTime maxDate = dt.AsEnumerable( )
。其中(r = > r.Field< string>( Column1)== someValue
。选择(r = > r.Field< string>( column2))
.Max();





http://msdn.microsoft.com/en-us/library/bb386977.aspx [ ^ ]


< blockquote> ypu可以使用LINQ用于此目的,但我认为这是与LINQ相比最快的方式

  int  minAccountLevel =  int  .MaxValue; 
int maxAccountLevel = int .MinValue;
foreach (DataRow dr in table.Rows)
{
int accountLevel = dr.Field< int>( AccountLevel );
minAccountLevel = Math.Min(minAccountLevel,accountLevel);
maxAccountLevel = Math.Max(maxAccountLevel,accountLevel);
}


使用Linq:



在C#中学习linq

LINQ to DataSet中的查询


Hi,

How to select the Max value in the data table column and also including where statement in c#.

Thanks,
Sivasankaran G

解决方案

DateTime maxDate = dt.AsEnumerable()
            .Where(r => r.Field<string>("Column1") == "someValue")
            .Select(r => r.Field<string>("column2"))
            .Max();



http://msdn.microsoft.com/en-us/library/bb386977.aspx[^]


ypu can use LINQ for this purpose, but i think this is fastest way as compare to LINQ

int minAccountLevel = int.MaxValue;
int maxAccountLevel = int.MinValue;
foreach (DataRow dr in table.Rows)
{
    int accountLevel = dr.Field<int>("AccountLevel");
    minAccountLevel = Math.Min(minAccountLevel, accountLevel);
    maxAccountLevel = Math.Max(maxAccountLevel, accountLevel);
}


use Linq :

learn linq in C#
Queries in LINQ to DataSet


这篇关于如何在Datatable中选择语句c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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