Click here to Skip to main content
15,306,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to validate data table row is unique or not.i finish the validation but the problem is if any empty values in fields throw error message.
How to validate only values.if empty value is occur just ignore it.

What I have tried:

C#
var duplicates1 = dtPart.AsEnumerable().GroupBy(r => r[7]).Where(gr => gr.Count() > 1).ToList();
duplicates1 = dtPart.AsEnumerable().GroupBy(r => r[7]).Where(gr => gr.Count() > 1).ToList();
Posted
Updated 7-Oct-16 23:52pm
Comments
OriginalGriff 8-Oct-16 5:12am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
You need to explain what is in your DT that is giving your problems - we can't look from here!
Use the "Improve question" widget to edit your question and provide better information.
Raja Ganapathy 8-Oct-16 5:59am
   
Okay sir!
manu_dhobale 8-Oct-16 5:31am
   
Well don't see any issue, even if there is null or empty value it will work.
please share whats there in your datatable. also share complete error message
Maciej Los 8-Oct-16 5:44am
   
Does the data type of r[7] field is numeric or string?
Raja Ganapathy 8-Oct-16 5:59am
   
Numeric

1 solution

Check this:

C#
var duplicates1 = dtPart.AsEnumerable()
     .Where(r => r[7]!=null)
     .GroupBy(r => r[7])
     .Where(gr => gr.Count() > 1)
     .ToList();


or:
C#
var duplicates1 = dtPart.AsEnumerable()
     .Where(r => r.Field<data_type>("FieldName")!=null)
     .GroupBy(r => r.Field<data_type>("FieldName"))
     .Where(gr => gr.Count() > 1)
     .ToList();
   

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