這個linq語法是之前在寫winform程式時,將DataSet的資料再整理過後,轉成dataTable的語法
可以當作以後參考用,先log下來
因為有時候在寫linq時,會忘記,得要把辛苦寫出來的結果留下來的好.
DataTable dt = (from x in dsResult.Tables[0].AsEnumerable()
where DataTrans.CBoolean(x["IsChecked"]) == true
group x by new
{
no = x.Field<string>("NO"),
ptno = x.Field<string>("PTNO"),
ver = x.Field<int>("VER"),
kd = x.Field<string>("KD"),
que_da = Convert.ToDateTime(x.Field<DateTime>("QUE_DA").ToString("yyyy/MM/dd"))
} into g
orderby g.Key.no,g.Key.ptno,g.Key.ver,g.Key.kd,g.Key.que_da
select new
{
qty = g.Sum(x => Convert.ToInt32(x["QUE_QTY"])),
stock=g.Sum(x=>Convert.ToInt32(x["STOCK"])),
no=g.Key.no ,
ptno=g.Key.ptno,
ver=g.Key.ver,
kd=g.Key.kd,
que_da=g.Key.que_da
}).ConvertDataTable();
留言列表