0
我有3列数据表如下如何计算在C#.NET数组列表中的项目串
DataTable CheckFingerQty = new DataTable();
CheckFingerQty.Columns.Add("IDp",typeof(string));
CheckFingerQty.Columns.Add("Date", typeof(string));
CheckFingerQty.Columns.Add("Nobat", typeof(string));
for (int i = 0; i < arrn.Count; i++)
{
string[]a= arrn[i].ToString().Split(';');
string []aa =a[1].Split(' ');
CheckFingerQty.Rows.Add(a[0],aa[0],a[2]);
}
我从一个ArrayList读取并添加行到this.after,我想这GROUPBY与数据表IDP和日期,以便我用下面的代码,但它不为我工作arrn与下面的数据
"1;04/03/2017 12:25:03;first"
"1;04/03/2017 12:25:03;first"
"1;04/03/2017 12:25:03;first"
"1;04/03/2017 12:25:03;first"
"1;04/03/2017 12:25:03;second"
"1;04/03/2017 12:25:03;second"
"1;04/03/2017 12:25:03;second"
"1;04/03/2017 12:25:03;third"
"1;04/03/2017 12:25:03;third"
"1;04/03/2017 12:25:03;third"
"2;04/03/2017 12:25:03;first"
"2;04/03/2017 12:25:03;first"
"2;04/03/2017 12:25:03;first"
"2;04/03/2017 12:25:03;first"
"2;04/03/2017 12:25:03;first"
List<KeyValuePair<string, string[]>> CheckFingerQtyArray = new
List<KeyValuePair<string, string[]>>();
CheckFingerQtyArray = CheckFingerQty.AsEnumerable()
.Select(Row => Row["IDp"]).Distinct()
.Select(Id => new KeyValuePair<string, string[]>(
Id.ToString(),
CheckFingerQty.AsEnumerable()
.Where(Row => Row["IDp"].ToString() == Id.ToString())
// .Select(Row => Row["date"].ToString() + ";" + Row["day"].ToString() + ";" + Row["nobatkari"].ToString() + ";" + Row["pname"].ToString())
.Select(Row => Row["Date"].ToString() + ";" + Row["Nobat"].ToString())
.ToArray()))
.ToList();
1:
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
1:
"04/03/2017;second"
"04/03/2017;second"
"04/03/2017;second"
1:
"04/03/2017;third"
"04/03/2017;third"
"04/03/2017;third"
2:
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
"05/03/2017;first"
"05/03/2017;first"
2:
"04/03/2017;second"
"04/03/2017;second"
"04/03/2017;second"
"04/03/2017;second"
3:
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
"04/03/2017;first"
的这个输出是像下面
我想知道〜应变的量的数组列表GS第一和各IDP的第二次和日期 例如
1 04/03/2017 the count of first is 4
1 04/03/2017 the count of second is 3
2 04/03/2017 the count of first is 3
2 04/03/2017 the count of second is 4
2 04/03/2017 second is 2 and ...
我该怎么办this.please帮我
我看起来像所有这些都是需要的是truncate date to midnight:CheckFingerQty.Rows.Add(new object [] { int.Parse(a [0]), DateTime.Parse(a [1])。Date, a [2] }); – jdweng
什么不起作用? – jdweng
请检查有问题的例子。我想输出是这样的1 04/03/2017首先是4 1 04/03/2017第二的数字是3 2 04/03/2017计数的第一个是3 2 04/03/2017秒的计数是4现在你的代码只计数每个IDP.bot第一,第二和第三为每个IDp – amin