malam9384
(Mashkoor Alam)
December 21, 2023, 12:25pm
1
Hello Team, I have 2 datatable dt1 & dt2
dt1 have 4 column with data
Name
Location
Amount
Position
Raj
1000
Rahul
2000
Kisan
3000
dt2 have 2 column with data
Location
Position
Mumbai
C1
Dehli
B4
Patna
A1
I need to take dt2 column value from location & Position column and enter into dt1 Location & position column by Linq Query
@malam9384
try this once
dt1.DefaultView.ToTable(False,"Name","Amount").AsEnumerable.Zip(dt2.AsEnumerable,Function(a,b) dt1.Clone.Rows.add(a.ItemArray.Concat(b.ItemArray).ToArray)).copytodatatable
Note both datatable should have same rows
sanjay3
(Sanjay)
December 21, 2023, 12:43pm
3
Hi @malam9384
How about this
dtResult = (From row1 In dt1.AsEnumerable()
Join row2 In dt2.AsEnumerable()
On row1.Field(Of String)(“Name”) Equals row2.Field(Of String)(“Location”)
Select dt1.Clone().LoadDataRow(New Object() {
row1.Field(Of String)(“Name”),
row2.Field(Of String)(“Location”),
row1.Field(Of Decimal)(“Amount”),
row2.Field(Of String)(“Position”)
}, False)).CopyToDataTable()
Assign dt1=dtResult
Write range - dt1
malam9384
(Mashkoor Alam)
December 21, 2023, 12:53pm
4
Name & location two different column. so no need to check any condition like below line
row1.Field(Of String)(“Name”) Equals row2.Field(Of String)(“Location”)
@malam9384
if you want to use invoke code try this way
Dim counter As Int32
For Each r As datarow In dt2.AsEnumerable
dt1.Rows(counter).Item("Location")=r("Location").ToString
dt1.rows(counter).Item("Position")=r("Position").ToString
counter=counter+1
Next
output
malam9384
(Mashkoor Alam)
December 21, 2023, 4:47pm
6
Can you please share this workflow
system
(system)
Closed
December 24, 2023, 4:53pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.