如何在c#中的EXCEL文件中查找重复数据? [英] How to find duplicate data in the EXCEL File in c#?

查看:665
本文介绍了如何在c#中的EXCEL文件中查找重复数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上传excel文件。我想检查excel(Employee Id)中的列是否唯一。目前我正在将excel数据提取到数据集。

我想验证提到的列说员工ID。



试过这个选项:

I am uploading excel file. I want to check a column in the excel(Employee Id) is unique or not. Currently I am fetching the excel data to a dataset.
I want to validate the column mentioned say Employee Id .

Tried this option:

var duplicates = result.Tables[0].AsEnumerable()
                                            .GroupBy(r => r["MOLId"])//Using Column Name
                                            .Where(gr => gr.Count() > 1)
                                            .Select(g => g.Key);





但不能在MOL ID是要验证的列数据的地方工作,无论它是否唯一。



But not working where MOL ID is the column data to be validated whether it's unique or not.

解决方案

试试这个。



Try this.

var qry =  from p in tableName
           group p by p.columnNameinto grp
           where grp.Count() > 1
           select grp;

foreach (var product in qry)
{
    MessageBox.Show("Duplicate Found!");
}


这篇关于如何在c#中的EXCEL文件中查找重复数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆