如何在Datatable中选择语句c# [英] How to Select statement in Datatable c#
本文介绍了如何在Datatable中选择语句c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何选择数据表列中的最大值,还包括c#中的where语句。
谢谢,
Sivasankaran G
解决方案
DateTime maxDate = dt.AsEnumerable( )
。其中(r = > r.Field< string>( Column1)== someValue)
。选择(r = > r.Field< string>( column2))
.Max();
< 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();
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屋!
查看全文