I am new to C#. I am just looking for a function which is similar to the "merge" function in python, I've struggled a lot but still don't find an easy way.
My objective is to simply merge two tables to one table (keeping the column names), below is example:
Table #1: Person
Table #2: Car
car_number car_color
111 black
122 red
Target output table:
I have tried LINQ
var results = from table1 in person.AsEnumerable()
join table2 in car.AsEnumerable() on Convert.ToInt32(table1["car_number"]) equals Convert.ToInt32(table2["car_number"])
select new { table1, table2 };
But here the trouble is that the CopyToDataTable()
function is no longer supported. And it is difficult to save the results to datatable keeping column names.
I also checked the function "Merge" in C#
, but it seems it requires a column of primary keys which contains only unique values.