Link to home
Create AccountLog in
Avatar of countrymeister
countrymeister

asked on

Join on two datatables and List<T> in linq

How do I Join on two datatables and a list<string>

    var result = from dataRows1 in DataTable1.AsEnumerable()
                         join dataRows2 in DataTable2.AsEnumerable()
                         on dataRows1["ID"] equals dataRows2["ID"]
                         join dataRows3 in dataList.AsEnumerable()
                         on dataRows2["Code"] equals dataRows3[0]
                         select joinedTable.NewRow().ItemArray = new object[]{
                             dataRows1["ID"],
                             dataRows2["Code"],
                             dataRows2["Price"],
                           
                         };
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of countrymeister
countrymeister

ASKER

Thank you. I was able to do this in query statement

datRows3 is a List<string>
 var result = from dataRows1 in Table1.AsEnumerable()
                         join dataRows2 in Table2.AsEnumerable()
                         on dataRows1["ID"] equals dataRows2["ID"]
                         join dataRows3 in dateList.AsEnumerable()
                         on dataRows2["Code"] equals dataRows3
                         select joinedTable.NewRow().ItemArray = new object[]{
                             dataRows1["ID"],
                             dataRows2["Code"],
                             dataRows2["Price"],
                         
                         };