uniqueRows = (From row In dtData.AsEnumerable()
Group row By systemName = row.Field(Of String)("System Name") Into systemGroup = Group
Select systemGroup.First()).CopyToDataTable()
From row In dtData.AsEnumerable(): This part of the query converts your DataTable dtData into an enumerable collection of DataRow objects, allowing you to iterate over each row in the DataTable.
Group row By systemName = row.Field(Of String)(“System Name”) Into systemGroup = Group: Here, it groups the rows based on the value in the “System Name” column. It assigns the name systemName to each unique value in the “System Name” column, and it groups the rows with the same “System Name” value together, which results in a collection of groups.
Select systemGroup.First(): Within each group, it selects the first row. This is done because you want to retain all columns for each unique “System Name,” so selecting the first row from each group effectively keeps all the columns for each unique value in the “System Name” column.
.CopyToDataTable(): Finally, the CopyToDataTable method is used to convert the resulting collection of DataRow objects back into a new DataTable. This new DataTable contains the unique values in the “System Name” column while retaining all other columns from the original DataTable.
or use this syntax:
uniqueRows= (From row In dtData.AsEnumerable()
Group row By systemName = row.Field(Of String)("System Name") Into systemGroup = Group
Select systemGroup).SelectMany(Function(systemGroup) systemGroup).CopyToDataTable()