Get only column names from the datatable

How to Get only column names from the datatable
such that i can change the columns
please help me here

Hey @Chirag12 ,
YourDT.Columns will return you the column names in an array

Refer below thread too

Hope it helps you !

@Chirag12

hi

arr_columns=Dt.columns.cast(of DataColumn).select(Function(x) x.columnname).toarray

try this

cheers

1 Like

Hi @Chirag12 ,

You could also check the workflow in the below post :

If the above doesn’t satisfy your requirement, we would need more details on what is actually needed to be done regarding the column names.

You can try with the for each and further based on conditions you can change the ColumnNames

image

@Chirag12

Hi @Chirag12

Use the for each activity to iterate the columns of a datatable.
In the List of Items fields give like this Datatable.Columns

Check the below image for better understanding.
image

Hope it helps!!

hi,@Chirag12

BuildDt.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName).ToArray

@Chirag12

if you want to change columnname then use this in assign activity

datatable.columns("oldcolumnname).columnName=“your column name”

Hope this helps

1 Like

Hi

To get only the column names from a DataTable in UiPath, you can use the following steps:

  1. Use a For Each Activity:

    • Drag and drop a “For Each” activity onto your workflow.
  2. Set Up Variables:

    • Create a variable to store the column name. Let’s call it columnName and set its type to String.
  3. Loop Through Columns:

    • In the “For Each” activity, change the “Type Argument” to DataColumn.
    • For the “Values” property, use YourDataTable.Columns. This will allow you to loop through each column in the DataTable.
  4. Assign Column Names to Variable:

    • Inside the loop, use an “Assign” activity.
    • Assign columnName the value of item.ColumnName where item is the current DataColumn in the loop.
  5. Use Column Names:

    • Now you can use the columnName variable to access and change the column names as needed in your workflow.

Here’s a visual representation of what the workflow might look like:

For Each column in YourDataTable.Columns
    Assign columnName = column.ColumnName
    (Use columnName as needed)
End For Each

With this setup, you can loop through all the column names in your DataTable and use the columnName variable to make changes or perform actions based on the column names.

Thanks!

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