Add column to datarow

Hi all,
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?
Thanks

@Slavich,

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.

1 Like

Hi @Slavich

Use an AddDataColumn Activity - Please note- this will Add the DataColumn to the Datatable whose Row you are getting… Below is a sample

image .

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.

–
Mukesh

1 Like

@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?

Hi @Slavich

Do you want to add column to datatable or column to row?

1 Like

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.

–
Mukesh

1 Like

@Slavich,

You need to copy the values alone from the source datarow to the destination datarow.

desRow.ItemArray = sourceRow.ItemArray.Clone()
1 Like

Column to row

At the step of adding row to empty datatable - I recieve: Object reference not set to an instance of an object…

Please initialise the Datatable

-
Mukesh

1 Like

Receive exception: This row already belongs to another table

Please Follow the Link .

–
Mukesh

I was having this issue today and found a work around for adding a column or entry to a Data Row element. in an assign, use drDataRow(“ColumnName”) = “Column Value”. This helped me to build a Data Row after fighting the conventional conversion functions.