Duplicate data is unavoidable and it is not always possible to keep it away.
Sometimes it can be also that we are trying to get distinct values.
So how we do that?
We can use the below LINQ query to achieve it 🙂
dataTable new_dt =
old_dt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“columnWithDuplic”)).Select(Function(g) g.First).CopyToDataTableNote:
1.Useful when we are removing duplicates with respect to some “Column” name
2.Simply replace the “columnWithDuplic” with your required column name
OR
We can use the simple DefaultView Code too…
dataTable new_dt =
old_dt.DefaultView.ToTable(True)
Note:
Useful when we are removing duplicates with respect to every “Column”
Example
Implementation using UiPath :
Assume we have a sample data, which includes information about 3 students.
Step 1:
Drag a “Build Data Table” activity into the design panel
Step 2:
Populate the “Build Data Table” activity with sample data
Step 3:
Create a variable of DataTable type with some name and supply it to the Output property of “Build Data Table” activity
Step 4:
Drag “Assign” activity into the design panel and in the “Value” property of that activity use the above code with proper values
Note: Here we are using the “Name” column to remove the duplicates from the data table.
Step 5:
Drag “Output Data Table” and “Message Box” activity into the design panel and supply the appropriate parameters to display the data.
Step 6:
Final output!!!
Click here to download the Source Code…
Hope it has helped you…
Hi.it’s very useful to me thank you .
I have one more dough what if we want to find duplicates for particular string only in your case I want to find duplicates only “Sarath” not for david