I will need to return rows from DT1 which match with DT2 like following
DT1 column “Manufacturer” must match DT2 column “Mfr_No”
DT1 column “XX00” must be diffrent than column DT2 “YY00”
All other columns values on both datatables can be anything.
Is this possible? After we have result then return assign these rows to DT3.
Assign activity
LHS: Result | DataType: List(of Datarow)
RHS
(From d1 in dt1.AsEnumerable
Join d2 in dt2.AsEnumerable
On d1("Manufacturer").toString.Trim Equals d2("Mfr_No").toString.Trim
Where Not d1("XX00").toString.Trim.Equals(d2("YY00").toString.Trim)
Select r = d1).toList
then check within an if acitvity
Result.Count > 0
Then: dtResult = Result.CopyToDataTable
Else: dtResult = dtData.Clone
That is working just fine thanks. What about if I want to include some columns also from d2 to the new datatable? All columns from d1 and for example “col1” and “col2” from d2
prepare an empty datatable with Build datatable activity and configure the target datatable column structure (dt2 cols are on the end) - dtTarget
Assign activity, if logic as above
modified LINQ:
(From d1 in dt1.AsEnumerable
Join d2 in dt2.AsEnumerable
On d1("Manufacturer").toString.Trim Equals d2("Mfr_No").toString.Trim
Where Not d1("XX00").toString.Trim.Equals(d2("YY00").toString.Trim)
Let ra = d1.ItemArray.Concat(new Object(){d2("col1"), d2("col2")}).toArray
Select r = dtTarget.Rows.Add(ra)).toList
Thanks a lot this is working also. Another question not related to previous one; is it possible to use LINQ to calculate price difference at one datatable between two columns and assign difference to difference column:
columns:
price
new_price
difference
I can do this using for each but is it possible to do also using LINQ