I have duplicate values which are in this format in a data table
Sak Dte
1 12/31/2020
2 12/31/2020
3 04/01/2020
3 12/31/2020
I need to remove Sak 3 with 04/01/2020 value from the data table . Below is the code I am using but it is removing Sak 3 with 12/31/2020 values any ideas how to solve this issue. Note: If you find similar sak value you need to remove the past date (dte)value and keep the future date (dte)value .ex: sak 3 has 04/01/2020 and 12/31/2020 in this we need to remove 04/01/2020 and keep 12/31/2020 Expected O/P Sak Dte 1 12/31/2020 2 12/31/2020 3 12/31/2020
private DataTable RemoveDuplicateRows(DataTable table)
{
List<DataRow> rmList = new List<DataRow>();
Dictionary<long, long> dictionary = new Dictionary<long, long>();
foreach (DataRow row in table.Rows)
{
long sak = Convert.ToInt64(row["Sak"]);
if (dictionary.ContainsKey(sak) == false)
{
dictionary.Add(sak, sak);
}
else
{
rmList.Add(row);
}
}
foreach (DataRow row in rmList)
{
table.Rows.Remove(row);
}
//Datatable which contains unique records will be return as output.
return table;
}