Sample input:
dt1 has 10 rows with below columns
Emp ID, Name, Area - out of these Column ‘Name’ is empty
dt2 has 5 rows with below columns
Emp ID, Name, Location
I have to perform left join and need output in the same dt1
dt1 should have same 10 rows with all the columns
Emp ID, Name, Area but only for the matched empIDs in dt2 , Name column in dt1 should be filled
i did check this video, since he has done with the same number of rows in both the data tables, it is not the exact solution to my problem. And also the common column values are all matching with both the tables and hence he got all the rows.
But in my case i have less number of rows in dt2 and when i try to execute the query i am only getting the matching rows …rest of my rows in dt1 are not coming
When i try to use the code which you gave @arivu96 getting the below
Error ERROR No compiled code to run
error BC36639: ‘ByRef’ parameter ‘dt2’ cannot be used in a lambda expression. At line 3
error BC36639: ‘ByRef’ parameter ‘dt2’ cannot be used in a lambda expression. At line 4 _Test.xaml
(From d1 In dtData1.AsEnumerable
Group Join d2 In dtData2.AsEnumerable
On d1("ID").toString.Trim Equals d2("ID").toString.Trim Into gj = Group
From g In gj.DefaultIfEmpty
Select ra = {d1("ID"), d1("Area") ,If(isNothing(g), Nothing, g("Name")) }
Select dtResult.Rows.Add(ra)).CopyToDataTable
dtResult is then the reconstructed DataTable as described as approach in the shared Blog
As an alternate Option you can also create a LookUp Dictionary and use it for the name retrieval.
I even tried the query you gave, but still its giving me only matched rows in dt1 instead of the whole dt1. Sorry i am bit slow learner if this is bothering you…but i understood the query and implemented the same…still its not giving me the desired output.
Is there any other way we can make a modification in the query because we can actually get this using nested for each but query seems the optimized way and faster…so trying for that