dataset 转linq 分组查询及求和
sql='SELECT part_no, qty, Curr, CONVERT(varchar(100), order_date, 23) AS order_date FROM order_detail_total where doc_no in ('SCN121200001','SCN121200002','SCN121200003') And qty <> 0'
dataset set=...(sql);
var q = from n in set.Tables[0].AsEnumerable() select n;
我的思路是这样,如果我用dataset得出我想要的结果集,然后对这个结果集操作,可以减少数据库的查询,以提高性能
1.我要实现SELECT part_no, sum(qty), Curr, CONVERT(varchar(100), order_date, 23) AS order_date FROM order_detail_total where doc_no in ('SCN121200001','SCN121200002','SCN121200003') And qty <> 0
这样的效果,怎么用q来实现
2.是我要查出给定值A,比如这个A是10,
SELECT part_no, qty, Curr, CONVERT(varchar(100), order_date, 23) AS order_date FROM order_detail_total where doc_no in ('SCN121200001','SCN121200002','SCN121200003') And
qty <10
这个查出来的qty小于10,则把part_no显示出来
求高人指点,怎么用q 来实现
------解决方案--------------------var q = from n in set.Tables[0].AsEnumerable()
where new string[]{"SCN121200001","SCN121200002","SCN121200003"}.Contains(n.Field<string>("doc_no")
&& n.Field<int> !=0
select n;
这是过滤,至于1,2中要SELECT的具体字段,就直接写在select后边,用个匿名类保存一下