I have two strongly typed Datatable (dt1
):
|FirstName|LastName|Val1|Val2|
|Tony |Stark |34 |35 |
|Steve |Rogers |12 |23 |
|Natasha |Romanoff|2 |100 |
and the second (dt2
)
|FirstName|LastName|Val1|Val2|
|Tony |Stark |16 |5 |
|Bruce |Banner |2 |1 |
|Steve |Rogers |54 |40 |
I try to create a new Datatable where I add up the values for the persons. I need a outer join since I need all persons and the value in the second table is halved.
So the result should looks like:
|FirstName|LastName|Val1|Val2|
|Tony |Stark |42 |37.5|
|Steve |Rogers |39 |43 |
|Natasha |Romanoff|2 |100 |
|Bruce |Banner |1 |0.5 |
My approach was with LINQ:
Dim query =
from a in ds1.Table1
Join b in ds2.Table2
On a.FirstName + a.LastName Equals b.FirstName + b.Lastname
Select New With {
.FirstName = a.FirstName,
.LastName = a.LastName,
.Val1 = a.Val1 + b.Val1 *0.5,
.Val2 = a.Val2 + b.Val2 *0.5
}
But I dont get all persons with the approach. I also tried
Dim query =
From a in ds1.Table1
From b in ds2.Table2
Select New With{
Key .KeyName = a.FirstName + a.LastName = b.FirstName + b.FirstName,
.Val1 = a.Val1 + b.Val1 *0.5,
.Val2 = a.Val2 + b.Val2 * 0.5
}
Now I get many entries for each person. Could anyone help me get this done. I dont know if there is maybe another approach without Linq to solve this.