How to create a data column at specific location dynamically

how to create data column at a specific location dynamically
like without mentioning the column index can we mention like beside this column like that?

@anjani_priya

use invoke code activity to create a column dynamically

dt1.Columns.Add("ColumnName").SetOrdinal(3)

You can pass any index where you want to add the column

but the columnindex you are giving should not exceed the columns count

@anjani_priya

You cannot mentioned beside a specific column…but what you can do is get the column index ousing column name and then add 1 to it and create a column using that index

To get index of a column use assign with

Requiredindex = (From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray().indexOf("RequiredColumnName")

Here requiredindex is integer type and add 1 to it to get the next column index where new column needs to be added

Cheers


error

@anjani_priya

Try like this

Requiredindex = Array.IndexOf((From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray(),"RequiredColumnName")

Cheers

how should I mention in the invoke method
after the assign method

@anjani_priya

What is this .reqindex …you just need to specify the requndex +1

And pass the datatable to invoke method…please check here

Cheers

Capture13
I have added the material description column but its over writing the data

@anjani_priya

What do you mean?

cheers

my input data is first empty column then vala,material,totals,bun,totalv,crcy
i added material description column beside of material but the material description column didnt came empty

@anjani_priya

can you show you flow please

cheers

check this flow once.

can you check this once

@anjani_priya

is the new column not getting added or what is the issue?

cheers

Hi @anjani_priya

Create two variables

existingColumnName As String = “YourExistingColumnName”
newColumnName As String = “YourNewColumnName”

'Find the index of the existing column

columnIndex As Int32 = dtTable.Columns.IndexOf(existingColumnName)

Create the variable newColumn

newColumn As New DataColumn(newColumnName)

Add the new DataColumn to the DataTable
dtTable.Columns.Add(newColumn)

Use SetOrdinal to place the new column beside the existing column
This will move the new column to the position right after the existing column

If columnIndex <> -1
Then
newColumn.SetOrdinal(columnIndex + 1)