Loading

Linq合并两个DataTable

 var linqbitem = from wip in dt_onwip.AsEnumerable()
                        join bitem in dt_cos_bitem.AsEnumerable() on wip.Field<string>("item_no").Trim() equals bitem.Field<string>("item_no").Trim() into s
                        from t in s.DefaultIfEmpty()
                        select new
                        {
                            item_no = wip.Field<string>("item_no"),
                            item_class = wip.Field<string>("item_class"),
                            onwipqty = wip.Field<decimal>("onwipqty"),
                            avg_cost = (t == null) ? 0 : t.Field<double>("avg_cost")
                        };

 

----------------------------------------------------------------------------------------------

 var var_dt = from trdord in dt_trdord.AsEnumerable()
                     join per in dt_per.AsEnumerable() on trdord.Field<string>("ord_nbr") equals per.Field<string>("ord_nbr") into s
                     from r in s
                     select new
                     {
                         //trd_ord
                         ord_nbr = trdord.Field<string>("ord_nbr"),
                         plan_shp_date = trdord.Field<DateTime>("plan_shp_date"),
                         mo_required_date = trdord.Field<DateTime>("mo_required_date"),
                         item_no = trdord.Field<string>("item_no"),
                         ord_um = trdord.Field<string>("ord_um"),
                         ord_qty = trdord.Field<decimal>("ord_qty"),
                         shp_qty = trdord.Field<decimal>("shp_qty"),
                         detail_status = trdord.Field<string>("detail_status"),
                         //percent
                         MA = r.Field<string>("MA"),
                         D = r.Field<string>("D"),
                         E = r.Field<string>("E"),
                         MU = r.Field<string>("MU"),
                         PUR = r.Field<string>("PUR"),
                         MN = r.Field<string>("MN"),
                     };

 

 

posted @ 2011-12-20 13:36  GerryGe  阅读(2466)  评论(0编辑  收藏  举报