I want to change column name in datatable if column name contains "LOT NUMBER" note : i already achive this with for each activities i want do it by LINQ

image

i want to change column name in data table if column name contains “LOT NUMBER” not : i already achieve this with for each activities i want to it by LINQ

Hi

U can try something like this

Assign activity:

NewDataTable = (From col In YourDataTable.Columns.Cast(Of DataColumn)()
Let newColumnName = If(col.ColumnName.Contains(“LOT NUMBER”), “NewColumnName”, col.ColumnName)
Select NewColumnName).ToArray()

Then u can try with
For Each activity with column In NewDataTable

Inside that use a assign to change the column name

YourDataTable.Columns(column.ToString()).ColumnName = “NewColumnName”

Hope this helps
Cheers @shubham2

@shubham2

Assign DataTableVariable = (From col In DataTableVariable.Columns.Cast(Of DataColumn)()
Select If(col.ColumnName.Contains(“LOT NUMBER”), New DataColumn(col.ColumnName.Replace(“LOT NUMBER”, “NEW LOT NUMBER”)), col)).CopyToDataTable()

Try this hope it works

Thank You


although is not showing any error but i got error
image

please help

1 Like

@shubham2

You would have copied the exact formula from here…

If you look in the editor screenshot there are red marks in few places basically the error says the inverted comma used are wrong …please remove them and re add

Wrong -“
Right "

Also linq is not correct way to modify the column names…for each what you have done is what you need to do

The above provided methods also either use for each or create a new datatable with no data and you need to lod again

Cheers

I would recommend re type again the same expression
@shubham2

what will be the NewDataTable variable type , is it array of string?

If Need change column name you can try this way also easily

image

input i have given like this
image

output

image

@shubham2

Take assign activity and pass like this

dt.Columns(“LOT NUMBERS”).ColumnName = “Amount”

note = column name i have given as amount based on you can give

@shubham2

Oh yeah that’s a typo
It’s array of string
@shubham2

but how can i write this into datatable

It happens with this step
@shubham2

@shubham2

As mentioned earlier…for loop is the way to convert the name…which you already tried and acheived…no linq method would be present

Cheers

in first expression we chang change the name but how we connect first expression to second one

yes it possible , but as you know headers are dynamic then we need to put if activity again which is i dont want

thank you for help