datatable group by
对datatable 里面的数据按某一特定的栏位进行分组并且按照某一规则
var query = from t in rate.AsEnumerable()
group t by new { t1 = t.Field<string>("Kind") } into m
select new
{
Kind = m.Key.t1
};
if (query.ToList().Count > 0)
{
query.ToList().ForEach(q =>
{ //根据Kind的种类按时间排序
DataRow[] drx = rate.Select("Kind='" + q.Kind + "'", "Year desc ,Month desc");
dt.Rows.Add(drx[0].ItemArray);
});
}
对于要满足datatable里面的同一栏位的两个值进行讨论时
首先对要进行讨论的栏位进行分组,在根据情况进行分类讨论
var query = from t in dg.AsEnumerable()
group t by new { t1 = t.Field<string>("P")} into m
select new
{
Prop_RateType = m.Key.t1,
};
if (query.ToList().Count > 1)
{
DataRow[] drTemp1 = dg.Select(" P='1'");
str1 = drTemp1[0]["Rate"].ToString();
DataRow[] drTemp2 = dg.Select(" P='2'");
}