Assign: Collection was modified; enumeration operation might not execute

Hi mates,

Here is my use case, I have the following DT
[Emp Id,Emp Name,Region,Region_From_DT2,Comments(c1=D1)
1001,Uma Sekh,Ind,Ind,
1024,Prabhash Ali,UK,Ind,
1178,Akram Kapoor,US,US,
]

the last column would be updated as True or False based on columns “Region” and “Region_From_DT2” matching

I tried this query
(From row In dtOutput Let A=If(row(“Region”).ToString.Equals(row(“Region_From_DT2”).ToString),“True”,“False”) Select dtOutput.Rows.Add(row(“Comments(c1=D1)”),A)).CopyToDatatable

I am getting the following error
“Assign: Collection was modified; enumeration operation might not execute.”

What would be the solution for this? I want to skip the for each loop activity.

Regards,
Sourav

@learning_sourav

Can you share the sample input so that i can help

Or you can try this once in invoke code

For each row as datarow in Dt.asenumerable
If(row(“Region”).ToString.trim.Equals(row(“Region_From_DT2”).ToString.trim) Then
row(“Comments(c1=D1)”)=“True”
Else
row(“Comments(c1=D1)”)=“False”
End if
Next

1 Like

@learning_sourav

If want to try with linq try this in assign activity

Dt.asenumnerable.select(function(a) dt.clone.loaddatarow({a(0).tostring,a(1).tostring,a(2).tostring,a(3).tostring,if(a(2).tostring.trim.equals(a(3).ToString.trim),“true”,“false”)},false).CopyToDataTable

Hope this helps

Thaks for the quick response,

I have tried the LINQ, can you suggest me if am I doing anything wrong here, looking to the ss

Typo
grafik

vs.

AsEnumerable

@learning_sourav

Use

Dt.AsEnumerable

Check the name of the AsEnumerable

I have used this query
dtOutput.AsEnumerable.select(function(a) dtOutput.clone.loaddatarow({a(0).tostring,a(1).tostring,a(2).tostring,a(3).tostring,if(a(2).tostring.trim.equals(a(3).ToString.trim),“true”,“false”)},false).CopyToDataTable

still getting the same error, would you check please?

@learning_sourav

Try the below expression

dtOutput.AsEnumerable.select(function(a) dtOutput.clone.loaddatarow({a(0).tostring,a(1).tostring,a(2).tostring,a(3).tostring,if(a(2).tostring.trim.equals(a(3).ToString.trim),“true”,“false”)},false)).CopyToDataTable

1 Like

Thank you,

This query is working.

Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.