Clear specific column data in DataTable

Is there a way to remove data of a specific data column of a datatable while retaining the headers instead of removing and then adding back the data column?

Hi @junhao.tan ,

Please use the Clear Data Table activity https://docs.uipath.com/activities/docs/clear-data-table.
It removes the content, but keeps the column headers.

Best regards,
Marius

Hi Marius,

Thanks for the reply. I only want to clear a specific column data while retaining the headers and not the entire Data Table.

Hi @junhao.tan ,

Then you can use a combination Remove Data Column (https://docs.uipath.com/activities/docs/remove-data-column), and then Add Data Column (https://docs.uipath.com/activities/docs/add-data-column )

Hope this helps
Best regards,
Marius

1 Like

Hi Marius,
Thanks for coming back.
I already understand the solutions you have proposed and stated in my original question:

“Is there a way to remove data of a specific data column of a datatable while retaining the headers instead of removing and then adding back the data column?”

use invoke code

first click on Edit Arguments and follow the screenshot, and inside “Value” pass in your datatable object

Then click Edit Code, and paste this text
You can replace Column2 with the column you want to empty
dt.AsEnumerable().ToList().ForEach(Sub(row)row("Column2") = "")

1 Like

Thanks Jack for offering another alternative!
It seems your solution can be achieve via for a For each row and assigning “” back to row(“ColumnName”) as well.

I was wondering if there’s something to the effect of dt.columns(“ColumnName”).Clear instead.

Yes, for each row activity works too, but if you want to do it in one line i would use
dt.AsEnumerable().ToList().ForEach(Sub(row)row("Column2") = "")
, and im not sure whether theres something like dt.columns(“ColumnName”).Clear

Thanks Jack! I understand and appreciate your intentions.

I am wondering the same too hence, the post :slight_smile: