I have a data table which has duplicate row as follow.
| | | | | |
|cid | usrnme | pname | prate | cabin |
|-----------------------------------------------------------|
|c11 | demo1@gmail.com | sample1 | 2000 | B2 | *******
|c14 | demo2@live.com | sample2 | 5000 | B3 |
|c15 | demo3@yahoo.com | sample3 | 8000 | B2 |
|c11 | demo1@gmail.com | sample1 | 2000 | B2 | *******
|c18 | demo4@gmail.com | sample4 | 3000 | L1 |
|c11 | demo5@gmail.com | sample5 | 7400 | B4 | &&&&&&&
============================================================
NOTE : there are different data for same ID ,see &&&&&&& row
How to get one row for above duplicate two rows.I have tried This
this is the code I used.
public DataTable RemoveduplicateRows(DataTable dTable,string colName)
{
colName = "cabin";
Hashtable hTable = new Hashtable();
ArrayList duplicateArrayList = new ArrayList();
foreach(DataRow drow in dTable.Rows)
{
if (hTable.Contains(drow[colName]))
duplicateArrayList.Add(drow);
else
{
hTable.Add(drow[colName], string.Empty);
}
}
foreach (DataRow dRow in duplicateArrayList)
dTable.Rows.Remove(dRow);
return dTable;
}
if I used above code it avoid duplicate according to cabin
then it removes all records which its cabin is B2 and keep the first one only.what I want is to remove only the full row(keep one and delete others).how can I do that.