How To Get Only Headers From A Datatable In UiPath

Some times you might want to copy the schema of one excel to another excel.

Let’s see how to do that with UiPath…

dt_New=dt_Original.Clone

Example

Implementation using UiPath :

Let us implement a workflow which takes a “ DataTable “ and displays the “ Headers ” of it.

Step 1:
Drag “Build Data Table” activity into the design panel and populate it with some sample data.

image

Step 2:
Drag “Assign” activity into the design panel and fill it with above-mentioned code.

image

Step 3:
Drag “Output Data Table” activity into the design panel and convert Datatable to String type

image

image

Step 4:
Drag “Message Box” activity into the design panel to display the reversed data table.

image

Step 5:
Finally, let’s run the project.

image

Hope it has helped you!

4 Likes

Why would you go to all that trouble when you can just do…

String.Join(",",(From dc In myDT.Columns.Cast(Of System.Data.DataColumn) Select dc.ColumnName).ToArray())

There are people who are not so well versed wilth VB.net function , hence they could not write complex code to get the outcome.

Therefore, in things could be achieved without writing much code then nothing is better than that.

It’s better to just learn the simple one-line solution.

Also…

Some times you might want to copy the schema of one excel to another excel.

Let’s see how to do that with UiPath…

dt_New=dt_Original.Clone

That doesn’t copy the schema of one Excel to another. That clones a datatable.

Here the schema refers to the table which have only headers and no data in it. It’s the database terminology.

Any it’s not easy to learn one liner code for each solution.

It took me 10 seconds to find it in the forums. It’s a common request.

You could also just do it this way without all the cloning etc.

image

image

We know that there are n number of ways to achieve anything.

None of the method is good or bad.

Creating unnecessary variables and code is bad.

So why are so many RPA tools turning to user-friendly usage? For example why is there a filter data table? dt.Select also works.

I gave a user friendly example (using activities) that is much simpler.

You just didn’t share. You have unfairly criticized a useful post. If you have a different solution, I think everyone will be pleased if you share it. The user can choose which one to apply.

1 Like

Criticism is an important part of improvement. It’s important to explain WHY you are showing a different way to do something.

Criticism is important, but the way you do it is more important. If you want to add something to the other person, you can express it better.

1 Like

I apologize if I was offensive. It was not my intent.