Filtered datatable modify records in original datatable


I have this
For row in dt.Select(“[NeedModification] = ‘needFrontEnd’”).CopyToDataTable

IF something a = 1,
row([NeedModification]) = “OK”

IF something a = 2,
row([NeedModification]) = “ERROR”

Write dt to CSV

The problem is that when I write dt to CSV, whatever I’d done in the filtered data table was not reflected in dt - meaning “OK” and “ERROR” are not showing in the CSV. The filtered data table is base on [NeedModification] = “needFrontEnd”.

I know I can assign the filtered data table to filterDt = dt.Select(“[NeedModification] = ‘needFrontEnd’”).CopyToDataTable

And then write filterDT in CSV. But I also want dt to ouput in CSV… This way I may have two CSVs instead which is not ideal.

But can I achieve this without creating a seperate data table output?

You can use simple assign activity -

dt = dt.Select(“[NeedModification] = ‘needFrontEnd’”).CopyToDataTable

But I still have information in dt that I have to keep.
Basically, in dt, I do somthing, and have some information for some rows but not some rows. For the rows that need more inforamtion which are [NeedModification] = ‘needFrontEnd, I have to do further check.
Therefore, I wonder if I can update in dt instead of creating a new dt

when you are updating the values in the original datatable, use
dtTable.Rows(dtTable.Rows.indexOf(filteredRow))(“YOUR_COLUMN”) = Value

In other way, if you have a unique value column in the table, then you can use Lookup Data Table activity to get the row index from the original datatable

Hello Madhavi,

This is what I was doing:

For row in dt.Select(“[NeedModification] = ‘needFrontEnd’”).CopyToDataTable

IF something a = 1,
row([NeedModification]) = “OK”

IF something a = 2,
row([NeedModification]) = “ERROR”

Write dt to CSV

So, where should I put dtTable.Rows(dtTable.Rows.indexOf(filteredRow))(“YOUR_COLUMN”) = Value


Try like this:

// assign the select result to an array of datarows
DataRow() filteredRows = dt.Select("[NeedModification] = ‘needFrontEnd’") 
foreach row in filteredRows // remember to set foreach type to DataRow, do not use foreachrow activity but regular foreach
// your if conditions stay as-is inside this foreach

// Write dt to csv
DataTable filteredDataTable = filteredRows.CopyToDataTable()
// Write filteredDataTable to second csv

Your issue was because .CopyToDataTable() creates a completely new datatable, including a deep copy of all the rows (as in they have nothing in common aside of having the same values, they’re completely separate objects).
So to do what you want, as far as I understood it, you need to first modify the rows and then create the second datatable.

This won’t work for the same reason as listed above (the new and old dt are completely separate). filteredRow, due to being a new object and not a reference to the old row, does not exist in the original datatable and thus you’ll get in return from .IndexOf call -1, which isn’t a valid row index and it will error out.

arDataRow = dt.Select(“[NeedModification] = ‘needFrontEnd’”)
Don’t convert the rows to a datatable after filtering. Instead use for each loop to iterate through the array of datarow, the output of Select filter.

for each row in arDataRow

IF something a = 1,
dtTable.Rows(dtTable.Rows.indexOf(filteredRow))([NeedModification]) = “OK”

IF something a = 2,
dtTable.Rows(dtTable.Rows.indexOf(filteredRow))([NeedModification]) = “ERROR”

Write dt to CSV