Updating values for duplicate item in a excel using LINQ

Hi there,

I am trying to update a data for common values in a excel or DT, how can I achieve this via LINQ

for example
I have to update the values to all the duplicate item on the field, the values for Column1 will be derived from a variable and it will be same for all the values having same value on column2



We can remove the duplicate values by using following method

DtNew = Dt.DefaultView.ToTable(True)

This will remove the duplicates from entire table…

Updating the duplicates can be possible using Normal activities like For each row and Write cell

If you need i can give you the solution using normal activities…


I don’t wanna remove duplicate values, I wanna update values to Column1 for all the duplicate values on Column2.

initially I will have Column1 as blank but column2 will have data, like below image, where on processing data for the 1st item Flipkart I will get values for Column1 in a variable(string) and I want to update that values to all the duplicate item on column2.

Make sense?

in general, we would recommend combining LINQ and essential activities like:

Groups | List(of List(of DataRow)) =

(From d In dtData.AsEnumerable
Group d By k=d(1) Into grp=Group
Select g = grp.toList).toList

for the update, we can prepare e.g. a dictionary, where the key is a group key like

new Dictionary(Of String, String) From {{“Amazon”,"…},…}
and can use it as
mrow(0) = dictLK(mrow(1).toString)

We used this technique also on huge data volumes and it was executed fast enough. In rare cases, we switched to Parallel For each for the group processing (outer loop)

Also we would implement some logic handling non present keys in the LookUp Dictionary

With the payoff of DataTable reconstruction and Blackboxing a prototype LINQ maybe also can be formulated.

But critical checking the case it is similar to a

  • A: update all rows first col depending on rows second col value
  • B: update filtered rows first col depending on rows second col value

where case A can be done in a for each along with this dictLK approach
where case B can be done on the filtered datatable row set with a variable

Also have a look here: