How to add DataColumn at 0 index in existing DataTable?

datatable
studio

#1

Folks,

Hope you are coding well. :slight_smile:

Currently, I am working on DataTable operations, but facing one issue.
Looking to add DataColumn at 0th index, but I am not able to do this.
I am trying by SetOrdinal method but not working.
Untitled33


#2

Hey @ganeshatkale

You have to pass it like dataTable.Columns.Add(“New_Col”).SetOrdinal(0).

datatable.Columns.Add("Col_Name", System.Type.GetType("System.String")).SetOrdinal(0)

For your Reference: Datacol_at_0_index_sample.xaml (7.1 KB)

Regards…!!
Aksh


#3

Thanks Aksh for the reply.
Actually code shared by you, I have already tried.
Please let me know, where I have to pass this line
datatable.Columns.Add(“Col_Name”, System.Type.GetType(“System.String”)).SetOrdinal(0)


#4

What you have tried? That is working :slight_smile:

and

This is the same even if you will not pass the column datatype in second argument it will default string type :slight_smile: what i have observed.

even if you want that one then here you can find.

Datacol_at_0_index_sample.xaml (7.0 KB)

Regards…!!
Aksh


#5

Thanks Aksh for the reply.
Yes, your piece of code worked for me.
I was forgot to add Parameters property for ‘Invoke method’ activity.
In there, I just added In, Int32 and 0.
Thanks a lot.