1

I have this datatable (RadkyData):

Name     EAN   PRICE
ITEM1   12345   10
ITEM2   5558    55
ITEM3   12345   44

I need to search rows with duplicate value EAN.? (a list of all EAN that are duplicate) I have this code:

var polozkySum = RadkyData.AsEnumerable()
                    .Select(r => new
                    {
                        c2 = r.Field<string>("EAN")
                    })
                    .GroupBy(g => new { g.c2 })
                    .Select(x => new
                    {
                        col2 = x.Key.c2
                    });

Have you any ideas please?

Daniela
  • 13
  • 3

2 Answers2

1
var rowsWithDupEAN = RadkyData.AsEnumerable()
    .GroupBy(row => row.Field<string>("EAN"))
    .Where(g => g.Count() > 1)
    .SelectMany(g => g);

If you don't want the rows but only this column values(as mentioned in a comment):

var dupEanList = RadkyData.AsEnumerable()
    .GroupBy(row => row.Field<string>("EAN"))
    .Where(g => g.Count() > 1)
    .Select(g => g.Key)
    .ToList();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

You can use LINQ to DataTable.

 var result = Radkydata.AsEnumerable()
             .GroupBy(r => r.Field<string>("EAN"))
             .Select(g => g.First())
             .CopyToDataTable();