Insert a Column into a specific position in DataTable

How can I insert a Column into a specific position in a DataTable ?

@certified

Hi @sishiramishra,

You can achieve it using AddDataColumn activity and SetOrdinal method.
Here is an example:
InsertColumn.xaml (7.4 KB)

Please go through with these links :slight_smile:

Regards,
Susana

Hello Susana , can you check your .xaml maybe the link is broken.

Regards

Hi @naotosx,

Here is a new example to insert a new column C between columns A and B.

InsertColumn.xaml (8.8 KB)

Let me know if you need something else :slight_smile:

Best Regards,
Susana

Thanks! just one question, i don’t know where you specify the position of the column C . if i’ve understood fine you create a Datatable, print it, insert new column C name C, value C1 into the datatable that you created and then reorder but i i want to know where you especify the position

Regards! :blush:

Hi @naotosx,

I have specified the position of the column using the method setOrdinal in the invoke method activity:

The DataColumn.SetOrdinal(Int32) method changes the ordinal or position of the DataColumn to the specified ordinal or position.

When you change a column’s ordinal, the column is moved to the new position in the collection of columns. Any columns between the previous and new ordinal will be renumbered, to adjust for a column’s new ordinal.

Best Regards,
Susana

Thank you so much! :heart_eyes::smiling_face_with_three_hearts: you helped me a lot!

Glad to help you @naotosx :star_struck::star_struck: