Hi,
I can share my code regarding removing duplicates:
Create a code stage.
input:
<type collection> Input name: CollectionIn
output:
<type collection> output name: CollectionOut
<type text> ErrorMessage
ErrorMessage = "";
CollectionOut = new DataTable();
DataTable dt1 = new DataTable();
try
{
dt1 = CollectionIn;
DataTable dtMerged = dt1.AsEnumerable()
.GroupBy(r => new {d= r.Field<string>("put here column name from your collection") })
.Select(g => g.First()).CopyToDataTable();
CollectionOut = dtMerged;
}
catch (Exception ex)
{
ErrorMessage = ex.Message.ToString();
}
Namespace Imports:
System.Linq
System.Reflection
System.Collections.Generic
External References:
System.Linq.dll
System.Data.Common.dll
System.Core.dll
System.Data.DataSetExtensions.dll
Hope this will help:)
------------------------------
MIROSLAW GADEK
CI & QUALITY MANAGER DACH
Schneider Electric Operations Consulting GmbH
Europe/Berlin
------------------------------
Original Message:
Sent: 07-02-2020 11:25
From: IAN NUGI
Subject: Collection - Remove Duplicated Values in Specific column
i have try your code but i got error, can you help me
------------------------------
IAN NUGI
Original Message:
Sent: 03-05-2020 08:05
From: Gopal Bhaire
Subject: Collection - Remove Duplicated Values in Specific column
Dim c As Integerc=Cint(cNumber)Collection_Out = Collection_In.AsEnumerable().GroupBy(Function(row) row(c)).[Select](Function(group) group.First()).CopyToDataTable()
Add cNumber as Number Input referring to column number starting from index 0
ALso add following to Imports
------------------------------
Gopal Bhaire
Analyst
Accenture
Original Message:
Sent: 03-05-2020 01:41
From: Mateusz Wojcik
Subject: Collection - Remove Duplicated Values in Specific column
Raúl Hernández thank you for this solution.
I am looking for less time consuming way, like extanding code Collection_Out = Collection_In.DefaultView.ToTable(True) by additional argument or additional line.
------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
Original Message:
Sent: 03-04-2020 10:13
From: Raúl Hernández
Subject: Collection - Remove Duplicated Values in Specific column
I understand.
In that particular case, you can use a simple loop logic to get unique values from the collection.
Simple loop logic should use
- A mirror collection, to compare all elements.
- A new collection to store unique values (entire row).
- A loop inside other loop, to compare all elements.
- a Flag to identify if the element already exist in your new Collection.
This logic is high time consuming depending of the numbers of rows in your collection, but it will work.
Original Message------
DISTINCT action return a collection with unique values and column counter
I lost others columns.
Please see attachments
------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------