Transferring a data table to a specific column of another

Hey there,

I have a scraped datatable under variable pScrapedOptionDT and I would like to put it into a different DT called ‘pOptionsDT’. The scraped data is taken from a specific header from a website and this value is stored, which correlated to pOptionsDT’s header names.

pOptionsDT has already been created and given headers correctly.

Essentially, I want to say:
'If pScrapedOptionDT column header X matches pOptionsDT column header X, add that scraped data to that column.

I added a for each to go through each column then added an ‘if’ to check the header, but then when I’ve done a ‘for each row in DT’ and added ‘add data row’, it hasn’t worked.

Can anyone explain what I need to input here? I think I may have the add data row section syntax wrong as it tells me that ‘Add Data Row: This row already belongs to this table.’ despite it being from one to another?

Thank you!

Hi @dr1992

You might have to create a new row in the new table and manually map all the values. You can create a new row for your table with dt.NewRow like so:
image

This might unblock your current workflow.


Apart from the unblocking part, wouldn’t the Merge Data Table fit here a bit better?

You could use a temporary table to extract the data in chunks, and then keep merging each chunk into the final data table until all the data is extracted.

we can simplify it and also omit the loop over the columns

If - myDataTableVar.Columns.Contains("MyColumnName")
then: For each row in pScrapedOptionDT
* Add DataRow: DataTable: pOptionsDT, ArrayRow: new Object(){CurrentRow("ColumnName"}

and also we could more condense the modeling, if needed

1 Like

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