I have 2 C# datatable:
Datatable A:
id | Name | Age | Height |
---|---|---|---|
01 | Pauls | 22 | 170 |
02 | Sam | 20 | 175 |
03 | Mike | 20 | 175 |
04 | Jame | 23 | 180 |
Datatable B:
id | Height | Age |
---|---|---|
01 | 175 | 23 |
02 | 190 | 21 |
The question here is how could I get this output by join 2 table A & B by id and get output datatable using Linq in C# OutputTable:
id | Name | Age | Height |
---|---|---|---|
01 | Pauls | 23(value in table B) | 175 (value in table B) |
02 | Sam | 21(value in table B) | 190 (value in table B) |
03 | Mike | 20 | 175 |
04 | Jame | 23 | 180 |
My code here:
var results = from ta in tableA.AsEnumerable()
join tb in tableB.AsEnumerable on ta["id"] equals tb["id"]
select new
{
ta["id"],
ta["Name"],
tb["Age"],
tb["Height"]
};
My output so far (not what I expected):
id | Name | Age | Height |
---|---|---|---|
01 | Pauls | 23(value in table B) | 175 (value in table B) |
02 | Sam | 21(value in table B) | 190 (value in table B) |
P/s: above table is just an example data, true data is bigger