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:


https://www.uipath.com/activities-guide/add-data-column

https://msdn.microsoft.com/es-es/library/system.data.datacolumn.setordinal(v=vs.110).aspx

Regards,
Susana

2 Likes

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

5 Likes

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:

2 Likes

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.

https://docs.microsoft.com/en-gb/dotnet/api/system.data.datacolumn.setordinal?redirectedfrom=MSDN&view=netframework-4.7.2#System_Data_DataColumn_SetOrdinal_System_Int32_

Best Regards,
Susana

18 Likes

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

1 Like

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

1 Like

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