Update the columns of datatable with another datatable using linq query

Hi All,
Can anyone please help on the below scenario with Linq query.
I am having master datatable which is having more than 20000 rows, with multiple columns.
i am having second datatable with distinct City names from city column of master Datatable and then i will generate ID for that and add another column as ID.

once i get that distinct city name and id[second datatable]
i should update all the rows which matches with the city in master datatable from the second table city column with ID in the second datatable…

For example-
City column- Bangalore will be there for 2000 rows, i should update in all the 2000 rows of the cityID column in the master table with the id which is there for Bangalore in second datatable.

Thanks in Advance.

Hi @M1288

Please refer the xaml

UpdateColumnsUsingLINQ.xaml (11.3 KB)

The LINQ used

	From row In dt_Master
	Let city = row("City").ToString.ToLower.Trim
	Let id = If(CityIDDict.ContainsKey(city), CityIDDict(city), "")
	Let ra = row.ItemArray.Reverse.Skip(1).Reverse.Append(id).ToArray
	Select dt_Result.Rows.Add(ra)

The Dictionary Assignment

CityIDDict = dt_Second.AsEnumerable.ToDictionary(Function(k) k("City").ToString.ToLower.Trim, Function(v) v("ID").ToString.Trim)

Hi @kumar.varun2,
it worked. Thank you

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