I have a 1 linq expression. In this, i want some columns from DT1 & some columns to DT2. i tried multiple ways but ended in vain.
Can anyone please help me with this!!
(From DT1 In dt1.AsEnumerable()
From DT2 In dt2.AsEnumerable()
Where DT1(14).ToString().contains(DT2(1).ToString())
Select DT2).ToArray().CopyToDatatable
AFAIK the array you use to create the new object could only reference to keys and agregated values (like in SQL). So you can not include any βdt1β value unless it is βgroup byβ key.
If i use that Colum in grp, then it tries to find a match. Since there is no match, i can not use that. And the 2nd option is aggregated values, in that it is string field and some time number, i cannot aggregate tat one.
We are in doubt on this statement. Bringing both datatables into a relationship requires a condition/rule for doing the pairing of dt1 and dt2 rows
Currently the case looks like following:
prepare an empty datatable with the 4 cols from dt1 and Col5 (representing Col4 from dt2) - dtResult
LINQ
(From d1 in dt1.AsEnumerable
Join d2 in dt2AsEnumerable
On d1(βCol3β).toString.Trim Equals d2(βCol3β).toString.Trim
Let ra = d1.ItemArray.Append(d2(βCol4β).toArray
Select dtResult.Rows.Add(ra)),CopyToDataTable
dt2 = (From row In dt1.AsEnumerable
Group row By keys = New With {
key .k1 = row.field(Of String)(βcol1β)}
Into gr = Group
Select dt2.LoadDataRow(New Object() {
keys.k1,
gr.FirstOrDefault()(βcol2β),
0,
gr.sum(Function(x) CDec(x.Item(βcol4β)))},
False)
).CopyToDataTable