I have a excel file, so I want to find non duplicated rows in excel by using linq,
Thanks and Cheers,!
I have a excel file, so I want to find non duplicated rows in excel by using linq,
Thanks and Cheers,!
(From row In dataTable.AsEnumerable()
Group row By key = row.ItemArray Into Group
Where Group.Count() = 1
Select Group.First()).CopyToDataTable()
Try this LINQ:
(
From row In input_dt
Group row By a = row("Column Name").ToString.Trim Into grp = Group
Where grp.Count > 1
Select grp.ToList
).SelectMany(Function(x) x).CopyToDataTable
Hope it helps!!
dtNonDuplicated = dt.AsEnumerable().GroupBy(Function(row) New With {
Key .Column1 = row.Field(Of String)("Column1"),
Key .Column2 = row.Field(Of String)("Column2")
}).Where(Function(g) g.Count() = 1).SelectMany(Function(g) g).CopyToDataTable()
Note:Please check The datatypes of your columns because here i take it as string but in your datatable it maybe of type Int,Double or string.
Try this:
(
From row In Input_dt
Group row By a = row("CName").ToString.Trim Into grp = Group
Where grp.count =1
Select grp.First
).CopyToDataTable
Cheers,!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.