Vlookup Linq failed for two datatable

Hi Folks,
I have two excel sheet I am trying to apply lookup using LINQ.
from dt1 I have fund name column and dt2 MID_FUND_NAME Column it should look up and fetch fund type from dt2 and update Fund code column into dt1

(From a In dt1.AsEnumerable()
Join b In dt2.AsEnumerable()
On a(“Fund Name”).ToString Equals b(“MID_FUND_NAME”).ToString
Select dt3.Rows.Add({a(“Plan#”),b(“FUND_TYPE”)})
).CopyToDataTable
Using these query not able to get fund code from dt2
Please find attached screenshot


Thanks & Regards

Hi @Akash_Javalekar1

Try this in Invoke Code activity

For Each row1 As DataRow In dt1.Rows
For Each row2 As DataRow In dt2.Rows
If row1("Fund Name").ToString() = row2("MID_FUND_NAME").ToString() Then
row2("FUND_TYPE") = row1("Fund Code")
End If
Next
Next

Regards,

What will be arguments?

@Akash_Javalekar1,

It should be dt1 & dt2 as DataTable Data Types. Directions would be In/Out

Thanks,
Ashok :slight_smile:

fund code not getting using invoke code I tried

@Akash_Javalekar1

If possible can you please share sample excel files

Regards,

Actually i am not able to share due to security as its confidential file

@Akash_Javalekar1

Code:

For Each row1 As DataRow In dt1.Rows
For Each row2 As DataRow In dt2.Rows
If row1("Fund Name").ToString() = row2("MID_FUND_NAME").ToString() Then
row2("FUND_TYPE") = row1("Fund Code")
End If
Next
Next

Fund code column getting empty in DT1

Any other linq to resolve this issue

@Akash_Javalekar1

Can you please try this

Code:

For Each row1 As DataRow In DT1.Rows
    Dim fundType As String = (From row2 In DT2.AsEnumerable()
                              Where row1.Field(Of String)("Fund Name").Trim().Equals(row2.Field(Of String)("MID_FUND_NAME").Trim())
                              Select row2.Field(Of String)("FUND_TYPE")).FirstOrDefault()
    If fundType IsNot Nothing Then
        row1("Fund Code") = fundType
    End If
Next

Regards,

@lrtetala It worked Thanks a lot for the support

Regards,
Akash Javalekar

1 Like

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