Adding column value from one table to another table without comparing two column

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

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

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

image

Can you please share this workflow

@malam9384

exceldata.zip (3.1 KB)

Please check this

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.