Hi guys! I have a question. How could I join two data tables into one? The difficulty of this is as follows:
Must contains ALL the data in DT1.
It must be filtered according to column N° Doc.
If the DT2 has a Doc No. that the DT1 does not contain, add to the DT3. Otherwise, do not add.
Don’t use filter for each activity with Filter data table activity (I used that method and these are usually tables of more than 100,000 rows. so it takes a long time and I am looking for something faster, like with LinQ, or else a faster method to process MANY rows and, using a foreach activity to check the N°Doc and then using a Filter Data Table activity to filter DT2, uses A LOT OF TIME) Libro1.xlsx (26.6 KB)
Could you tell me how to use them properly? Since I don’t know how to make the merge filter through the Doc No. column and not through the other columns.
For each or For each row are not slow. That is a myth. Yes linq query may be a little faster but I am quite sure the standard activites themselves use linq query in the background / source code. So looking to avoid using well structured standard activities is not what I would recommend. Standard activities are also easy to understand and comprehend than a linq query to all in your team / organisation. Nothing against linq, but the forum lately is so focused on using linq that they forget standard activities are not slow in comparision.
It looks like your case description and the requirements are mixed up with implementation portions.
Here we do see a clear requirement: dt3 will have all dt2 rows, where no dt1 exists for the particular DocNO
We can do it with join datatable
left: dt2
right: dt1
join type: left
and will use (afterwards we do a column removal on unneeded cols from join result) from Join result these rows where dt1 DocNo col is null/empty
doing it with LINQ give a try on:
dt3 =
(From dl In dtData2.AsEnumerable
Group Join dr In dtData1.AsEnumerable
On dl(1) Equals dr(1) Into gj = Group
From g In gj.DefaultIfEmpty
Where isNothing(g)
Select r=dl).CopyToDataTable
In case of empty results are expected CopyToDataTable is to shift to a more defensive approach e.g toList and Result.Count Check
So for this scenario we do use Join DataTable or a LINQ. But it is not recommended to re-implement a join datatable with a for each / filter construct.