Reputation: 3601
I've a datatable that has been filled by excel sheet, it has lots of product id's and some other data. I want to check if there is any duplicate product id in my datatable and tell user that these prodcuts ids are duplicates or something like that.
Lmbda, Linq , Looping anything will do.
Thanks
Upvotes: 0
Views: 2801
Reputation: 28530
Here's a slightly modified version of another answer C# Linq finding duplicate row:
var qry = from p in Products
group p by p.productID into grp
where grp.Count() > 1
select grp;
foreach (var product in qry)
{
// Do something as needed/desired
}
Products is the DataTable, productID is the product ID; substitute appropriate names from your code as needed. I haven't tested this, but it should at least get you pointed in the right direction.
Upvotes: 3