u will get a datatable with duplicates removed. post which you can use a simple linqu to get the results based on effective date.
Your LINQ query seems mostly correct. However, there are a few adjustments needed
- You need to specify the date formats for parsing correctly.
- “DateTime.ParseExact” method requires an array of formats, not just a single format string.
So the Query goes like this
var result = (from row in AdditionsReportDT.AsEnumerable()
group row by row.Field(“Associate ID”) into grp
let maxDateRow = grp.OrderByDescending(r => DateTime.ParseExact(r.Field(“Effective Date”), new string { “MM-dd-yyyy”, “MM/dd/yyyy” }, CultureInfo.InvariantCulture)).First()
select maxDateRow).CopyToDataTable();