nitin singh

nitin singh

  • NA
  • 19
  • 2.6k

SQL query returning 6 lac records, remove duplicare record

Dec 17 2018 3:16 AM

My SQL query is returning around 6 lac records. From these records I have to remove rows which Is having repeated value for one of the columns : AccountID. I am iterating through the dataset in C# code using for loop and deleting records by checking value of the column AccountID if it already exists. This process is taking very long time. Pls suggest alternate ways to remove the duplicate records based on the value of column: AccountID. I tried below code to remove duplicate rows by column value:

public DataTable RemoveDuplicateRows(DataTable dTable, string colName) 

{
Hashtable hTable = new Hashtable(); ArrayList duplicateList = new ArrayList(
);
foreach (DataRow drow in dTable.Rows)
{
if (hTable.Contains(drow[colName])) duplicateList.Add(drow);
else hTable.Add(drow[colName], string.Empty);
}
//Removing a list of duplicate items from datatable.
foreach (DataRow dRow in duplicateList)
dTable.Rows.Remove(dRow);
return dTable;
}

 


Answers (4)