I have a datatable filled with data.
In a for each loop I want to replace a value. How do I do this without exporting it to excel and using write cell activity?
Currently my loop looks like this. I wrote the datatable to csv after, but it doesn’t show the new values. I don’t get any error messages.
Assign activity is: row(4).ToString.padleft(4,CChar(“0”))
Is there column with index 4 in your datatable? Try Dt.Columns.Count to see if it exists. You can always add a column with a specific name for index 4 before going into ForEachRow.
I always find it more reliable to work with column names instead of indices (in case column order changes).
instead of row(4) I would use row("ColumnName")=row("ColumnName").ToString.padleft(4,CChar(“0”))
It is a legitimate question, because if your if statement never gets to the “true” side, then your assign activity will never trigger. Don’t forget that index starts at 0, so row(4) is actually the 5th column in the datatable.
I’m not 100% sure if it’s necessary, but try changing the right side of your assign activity to be row(4).Item.ToString.padleft(4,CChar("0")) instead,
Also, throw in a write line activity or something similar to show which path you are taking in your if statement. This can greatly help debugging your logic and is something i generally recommend doing all the time during development as it can be removed when tidying things up for the actual deployment
Yes, I undestand and thank you all for trying to help me make my project more readable.
I use write line a ton, which is something that is included in the commented out section.
Other than that, please let’s just stay on topic of what I’m trying to achieve
row(4).Item.ToString.padleft(4,CChar("0"))
This returns a compiler error: Option Strict On disallows late binding.
We are attempting to help you with the limited information you have given us. We gave the likely problem based on that limited information, and offered some direction on how to try to troubleshoot it to give us some more information. It seems like you know what you’re doing though, so good luck