How to check if a datarow already exists in datatable

Hi there, my robot writes datarows to a datatable. Now, I would like to add a condition, that it only adds the row if it doesn’t exist already in the table. How can I do this?

@Jizh
Let us take you are having a datatable dta and data row as dr

In if Condition

(From p In dta.Select
Where string.Join(",".p.ItemArray).Equals(string.Join(",",dr.ItemArray))
Select p).Count>0

If the count is greater than zero then the row already exists in the Datatable else the datarow is not present in the datatable.

Regards,
Mahesh

4 Likes

@MAHESH1 Thank you for the quick help. Is p the row? Should I put the p in a for each row activity?

@Jizh
No need, you just replace the entire query in If condition, just rename the datatable variable and datarow variable.

Regards,
Mahesh

It says that p is no member of string.
What am I doing wrong?
Regards,
Robin

1 Like

Hey @Jizh ,

It seems @MAHESH1 made a small error and placed a period where a comma should have been. This is what the code should look like.

(From p In dta.Select
Where string.Join(",",p.ItemArray).Equals(string.Join(",",dr.ItemArray))
Select p).Count>0