I receive a certain dataRow. I need to add a column at the end of this dataRow and afterwards to append the final row to the excel/csv.
What the better way to do that?
You need to create a final excel/csv model datatable first, then you have to copy the values from that input datarow to the new datatable datarow, then you can add this updated datarow to the Excel/CSV datatable.
Use an AddDataColumn Activity - Please note- this will Add the DataColumn to the Datatable whose Row you are getting… Below is a sample
Now you can use This Datatble to write inot Excel/Csv.
Also , You can copy the Actual dataTable , make a copy and then perform the above operations.
@sarathi125, I tried as you mentioned but recieve exception: row is a part of the other datatable… How to avoid such exception?
Is there a way yo add column just for the extracted row?
Do you want to add column to datatable or column to row?
A DataRow is a Part of DataTable , You Just cannot add a Column to dataRow.
The DataColumn is Added to a DataTable.
What you can do is Create a new datatable and then add datacolumn.
You need to copy the values alone from the source datarow to the destination datarow.
desRow.ItemArray = sourceRow.ItemArray.Clone()
Column to row
At the step of adding row to empty datatable - I recieve: Object reference not set to an instance of an object…
Receive exception: This row already belongs to another table
Please Follow the Link .