Hi all,
Hope you can help me solve this:
I have a Data Table where I need to remove duplicates in the column “Games” only if:
the column “Type” is NOT empty for that row.
Meaning: for each row in the DT we need to check if the “Type” value is not empty. If not empty then add to the “Games” column to remove duplicates.
In the end I need the original values back in the “Games” and “Type” column and Data table with the only change of the removed duplicates based on the “Type” column.
Hi,
I’m trying to use the below in assign to dt_GoodData. [dt_ItemsEmpty is the original dt I’m reading]. Any ideas why this is throwing errors?
dt_ItemsEmpty.Clone()
For Each row As DataRow In dt_ItemsEmpty.Rows
If Not String. IsNullOrEmpty (row("Type").ToString()) Then
Dim game As String= row("Games").ToString()
If Not dt_GoodData.AsEnumerable().Any(Function(x)x("Games").ToString()=game) Then
dt_GoodData.ImportRow(row)
End If
Else
dt_GoodData.ImportRow(row)
End If
Next row
Dim uniqueCombinations As New HashSet(Of String)()
Dim distinctRows As New DataTable()
distinctRows.Columns.Add(“Games”)
distinctRows.Columns.Add(“Type”)
For Each row As DataRow In In_DT.Rows
Dim games As String = row(“Games”).ToString()
Dim type As String = row(“Type”).ToString()
Dim combination As String = $"{games} {type}"
' Check if the combination is unique
If uniqueCombinations.Add(combination) Then
' If unique, add to distinctRows DataTable
distinctRows.Rows.Add(games, type)
End If
Next
’ Assign the distinctRows DataTable to the Out argument
Out_DistinctRows1 = distinctRows