Expression will not give any value

Hi guys,

i need to remove the data row by some condition i am using IF condition and all fine . Remove data row is throwing an error like collection was modified. so i need to use
Datatable.remove.rows(row) passing row as for each item.
But problem is how can i add this Datatable.remove.rows(row) method into my code like i cannot assign to anything, i am just tried to use in writeline but as expected it thrown error like this expression cannot give any value.

Please advise on above how can i use code Datatable.remove.rows(row).



  1. WriteLine is not for coding , it is for printing any log/line in execution log window
  2. in your case you should pass the same row to remove it using “Remove data row” activity or you can use row index as well
  3. for using "Datatable.remove.rows you can write the code in invoke code activity. or just assign back to same data table like dt= dt.Rows.Remove(row)(which is not a good practice)

Thank you so much.

Will you please tell me how can i use Datatable.remove.rows(row) in inovke code activity.

Please advise me on this

Hi @Sriram07

you can use remove data row activity instead of invoke code activity

  1. declare a list variable of type datarow
  2. use add to collection activity inside if block to add matched rows to list
  3. use for each loop above list and keep remove data row inside it.
1 Like

Yeah bro I have done already in this method because of I don’t know how to do it in invoke code activity…

So if anyone help me by using invoke code activity to delete the rows in the data table it would be very helpful for me …


@Sriram07 are you by chance doing this in a for each loop? The issue is not with the remove datarow activity, you are getting that error because you are trying to delete rows while iterating through your datatable. You can’t modify a datatable while iterating through it

A better approach is to filter your datatatable using a .Where() or .Select() statement, then use the .CopyToDataTable() if using the .Where() method, or to use the delete row activity if using the .Select() method.

A quick search here should show plenty of ideas on how to perform either of these activities. Let me know if you get stuck and I would be happy to help

Yeah Dave thanks so much!!!
Already solved with one of the methods you have said.

If anyone help me how can I do the same using invoke code activity, will be very useful and I can also understand this method also right.

That’s why, anyway thanks for all the effects.

@Sriram07 Invoke code just runs code that you write yourself. I would not recommend using that unless you and everyone else on the development team understands code and knows how to modify and maintain it. Almost everything can be done using the built-in activities instead.