Add unique entry in datatable

Dear Forum members,

I have a data table of two column named material and component with some existing data and at every next loop iteration i am adding some data in both column by using merge datable activity.

My requirement is that, new row only should be added if the column value of material is not present in existing data table, if the new row’s material column value is already present in data table then it should not be added.

Likei have a dadatable:
material component
A 1005
B 1006

and if a row comes with value A 1003
then it should not be added because of A is already there.

Thankx in advance

Hi @Yankit_singh !
I suggest you to use a list to avoid double values :smiley:
Here is an example of the way to use the list of string
Sequence.xaml (7.0 KB)
So in your datatable, inside the foreach row, you add in the list row("material").tostring
If the row(“material”).tostring already exist in the list(of string), then it will do nothing, else you have to add what you want to do.

Another way
Use Filter Datatable for this, check as below

Output to another datatable

after that check Datatable is returning any rows, If it returns any row then the datatable is having the values else no value

Hope this may help you


Thankx for response

I am using merge data table inside do while loop not in foreach

Sure, but the most important part in my xaml is the list option :wink:
Let me know if you don’t grab the use of a list

i guess you are using an if activity for check.

So in the condition field following statement can be used and will return true (value exists) or false (not present)

YourDataTable.AsEnumerable.Any(Function (x) x(YourColName).toString.trim.Equals(YourCheckValue))

1 Like

Thankx for response

I am merging two data tables dt1 and dt2 inside a do while loop and my requirement is that only those entry from dt2 should be merged in dt1 for which first column value is unique, rest of column value doesn’t matter.

like if dt1 have A 4002
B 1006
and dt2 have A 2003

then after merging these data tables dt1 should have same as before merge, because of A is already in dt1, it should not be added.

maybe we did you wrong, but lets retake your feedback:

given data:
material component
A 1005
B 1006

row to check:
A 1003

if activity - Condition:
YourDataTable.AsEnumerable.Any(Function (x) x(YourColName).toString.trim.Equals(YourCheckValue))

YourCheckValue for the row A,2003 is A and the statement will be true, as A already exists in dt1

then: do nothing
else: Add datarow

So this should work. In case of in the else branch a merge of entire dt2 will be done then for sure it risks to produce the wrong results

1 Like