Join two tables with C# linq

Hi,

I am having two tables as below.


I want to join these two datatables using c# linq with studentID as key and want
columns StudentID, StudentName and Course in result datatable.

Dt1
image
Dt2
image
Join dt
image
Took only needed columns
image
Output
image

Let me know if you are ok with this

1 Like

Using Linq query method

dt1
image
dt2
image
final dt just create column only without any data
image
Linq query

(From a In dt1.AsEnumerable() Join b In dt2.AsEnumerable() On a(“ID”).ToString Equals b(“ID”).ToString Select dt.LoadDataRow (New Object() { a.Field(Of String)(“ID”),a.Field(Of String)(“Name”),b.Field(Of String)(“Course”)},False)).CopyToDataTable

image

Check and let me know whether these two methods is helpful or not

1 Like

Thanks @ganesh4 . Actually I wanted to join tables using C# linq as I have chosen C# language for my uipath flow.

I hope this will work

If this is working, then can you mark the solution and we can close this case?

Hi,

C# expression will be the following. Can you try this?

(from a in dt1.AsEnumerable() join b in dt2.AsEnumerable() on a["StudentID"].ToString() equals b["StudentID"].ToString() select dt.LoadDataRow (new object[] {a.Field<string>("StudentID"),a.Field<string>("StudentName"),b.Field<string>("Course")},false)).CopyToDataTable()

Sample20210723-1.zip (3.1 KB)

Regards,

HI Ganesh, it is working but in VB.Net Uipath project, not in C# Uipath project.

Thanks @Yoichi! Its working.

1 Like

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