LinQ query or any other solution for converting first row of datatable as a haeder

Hii, Please help ASAP

I have a datatable my requirement is to convert the first row of the datatable as a header.
(Except: Add headers in read range property)

Please provide some solution

can you explain why you cant use add headers?

Hi @Dummy

Header will be always first row of the DataTable

If you want then in Read Range activity enable Add Headers in properties, So first row of the excel sheet will act as Headers

Hope this helps you


because this datatable (which currently i needed) is the filtered datatable.In previous datatable there are many columns but i needed only some of the columns and previous datatable does not have headers. So now in extracted datatable i need first row as a header

Can share the sample input screenshot @Dummy

As i understand maybe you can do it like this:

use write range activity and write the headerless datatable into an excel file,
then use read range. this way you can use add headers property.

this can be a dumb method but it should work

Hi @Dummy ,

Maybe you could provide us a Sample of what is the Input and what should be the Expected Output after Read Range, we could maybe direct you for a better approach.

However, If you require the 2nd row in Excel to be the Headers in Datatable, you could mention the Range starting from "A2" in Read Range Activity.

Let us know if this works for your case.

@Dummy ,

If following a Datatable Approach, an alternate also would be to rename using a For Each Loop like shown below :

  1. We Read the First row values from the Datatable using below Expression :
rowValues = DT.Rows(0).ItemArray.Select(Function(x)x.ToString).ToArray

Here, DT is the input Datatable, rowValues is a variable of type Array of String.

  1. Next, we use a For Each Activity and Iterate through the Current Column Names of the Datatable. We also assign an Index value to For Each Activity. Inside For Each we use an Assign Activity and rename the Column using rowValues(i) where i is the iterative number or index of each iteration.

To get the Column Names from Datatable :

DT.Columns.Cast(Of System.Data.DataColumn).Select(Function(x)x.columnName).ToArray

Visuals :

Let us know if you were able to find a successful method from the suggested methods.

No, this is not feasible solution