Karthi Keyan

Karthi Keyan

  • 998
  • 755
  • 236.7k

Remove Duplicate Rows From DataTable in c#

May 29 2017 5:51 AM
Hi,
 
   I have DataTable. That have 2 Columns. one is Element, another one is Attribute. Element Column have duplicate. but Attribute not. i want to remove Entire row if is there any duplicate in Element Column.  like Follow.
 
 Element Attribute
 component/header @[version = '1.2']
 component/header/title[cited = 'no'] @[type = 'series']   
 component/header/title[cited = 'no'] @[level = 'Product']
 
from this table i want remove 4th row. i tried to check while adding each row by DataTable.Select. but it return an error. because  the Element having single quotes. Also i tried  
dt.AsEnumerable().Distinct(DataRowComparer.Default);  but that's not help full. is there any idea about this. 
 
Thanks in advance. 

Answers (6)