I am working on a process where a .csv file is read into a datatable(1). In that datatable we then filter out rows that are already marked as complete and then save the remaining uncompleted rows as an array of datarows(2). We do this to save time unnecessarily iterating through rows we’ve already completed.
Next we use a ‘For Each’ activity to cycle through the new list of rows to update them and mark as complete.
With this done, we’d like to add the newly added information from the updated datarows (2) back to the original datatable (1)
Does anyone know how this might be done?
Currently, I can only seem to completely overwrite the original (1) with the new results(2) Instead we want to preserve the rows we filtered out and only add back in the updated rows.
This will give you an array of DataRow objects that are not marked as complete.
Process the Filtered Rows:
Use a For Each loop to iterate through dr_filteredRows and update the necessary information. Ensure that you update the data directly in the DataRow objects.
Update Original DataTable:
Instead of overwriting the original DataTable (dt_original), you can update the rows directly by
referencing their index.
Here’s how:
In your loop, identify the index of each DataRow from the filtered array and update the corresponding row in dt_original:
For Each dr In dr_filteredRows
dt_original.Rows(dt_original.Rows.IndexOf(dr))(“ColumnName”) = dr(“UpdatedColumnName”)
Next
Save the Updated Data:
After processing and updating, dt_original will now have both the unmodified rows (those that were previously marked as complete) and the updated rows (from the filtered and processed ones).
By following these steps, you ensure that the original
DataTable is not overwritten, and only the relevant rows are updated.