linq的join方法,List與DataTable的方法

  • 13906
  • 0
  • C#
  • 2010-11-04

linq的join方法,List與DataTable的方法

linq對於List及DataTable在做join寫法是不同的,try了很久(因本人比較苯的關係),所以趕快log下來囉!

泛型的範例

var var1 =  (from d10 in d0

                        join d11 in d1 on new { d10.companyno, d10.orderno, d10.itemno }

                                        equals new { d11.companyno, d11.orderno, d11.itemno }

                        where d10.status== "N"

                         select d1).ToList();

 

datatable的範例

DataTable   inbal = (from x in dt1.AsEnumerable()

                            join z in dt2.AsEnumerable()

                                 on new {companyno=x.Field<string>("companyno"),partno= x.Field<string>("partno") } 
                          
equals new {companyno=z.Field<string>("companyno") ,partno=z.Field<string>("partno") }

                             select x).CopyToDataTable() ;

 

這樣應該有人看來吧~微笑

‧覺得文章不錯請給我一個『讚』作為鼓勵喔!