Link to home
Start Free TrialLog in
Avatar of esak2000
esak2000

asked on

C# Left join 2 DataTables without knowing the content of each, just the join key

I have 2 C# DataTables that I want to left join in order to create a combined DataTable.
I know the name of the column that joins the table, but nothing else, as the use imports the 2 tables at startup. The joining column is 'UPC'

1. What is a code example to join the 2 tables together to a third DataTable with all columns?
2. If there are column with the same name in each table will it be a problem for the join? If so, is there any solution?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

SELECT T1.*, T2.* FROM T1  left JOIN T2 ON T1.UPC = T2.UPC

where T1 and T2 are the table names you have
>>If there are column with the same name in each table will it be a problem for the join?

NO, but you need to refer to them with the table names eg.
T1.x or T2.x  (so you know which field called x is coming from which table)
Avatar of esak2000
esak2000

ASKER

that's a standard sql query, I need the LINQ equivalent for .net datatables
ASKER CERTIFIED SOLUTION
Avatar of esak2000
esak2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This class worked as a solution worked to join the 2 datatables