Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
var duplicates = result.Tables[0].AsEnumerable()
                                            .GroupBy(r => r["MOLId"])//Using Column Name
                                            .Where(gr => gr.Count() > 1)
                                            .Select(g => g.Key);


But not working where MOL ID is the column data to be validated whether it's unique or not.
Posted
Comments
Sarath kumar.N 9-Sep-15 6:40am    
can u share your table details?
Maciej Los 9-Sep-15 11:30am    
Unclear! We need more details, because we can't read your mind or direct from your screen.

1 solution

Try this.

C#
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!");
}
 
Share this answer
 
Comments
Maciej Los 9-Sep-15 11:28am    
Is there any difference between your query and OP's query?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900