var query =
from rHead in mPlanDataTable.AsEnumerable() where rHead.Field<String>("line") == sqlLine.Text && rHead.Field<String>("product_req_ym") == dtpYmd.Text.Replace("/", "") && rHead.Field<String>("supplier") == rHead.Field<String>("usercd") && rHead.Field<String>("supplier") == sqlLine.Text.Substring(sqlLine.Text.Length - 4, 4) orderby rHead.Field<String>("itemno") group rHead by new { line = rHead.Field<String>("line") , itemno = rHead.Field<String>("itemno") , supplier = rHead.Field<String>("supplier") , usercd = rHead.Field<String>("usercd") , product_req_ym = rHead.Field<String>("product_req_ym") } into g select new { line = g.Key.line, itemno = g.Key.itemno, type = g.Key.itemno.Substring(0, 4), sy = g.Key.itemno.Substring(8, 6),supplier = g.Key.supplier,
usercd = g.Key.usercd, product_req_ym = g.Key.product_req_ym }; foreach (var obj in query) { mTempDataTable.Rows.Add(obj.line , obj.itemno , obj.type , obj.sy , obj.supplier , obj.usercd , obj.product_req_ym); } }