Maintaining column headers after clearing Datatable

Hi All,

I have a Data table which is read using Read Range activity with headers. I want to reuse the same data table. i.e. I want the same column header names; but without the data so that new data can be read into it.
I have tired using datatable.Clear(). But this method only maintains the structure of the datatable (No. of columns) but not the name of the headers.

Is there any way to maintain the same headers for the datatable?

Hello @pearlb,

Have you tried using DataTable.Clone method?

CloneDataTable.xaml (11.7 KB)

Regards,
Susana

4 Likes

Hello,

If you don’t want to create another DataTable, you can call method myDataTable.Rows.Clear. Also, please verify if AddHeaders property is checked in Read Range activity, maybe you never have the column headers to begin with (unlikely but worth checking).

2 Likes

Hi Susana,
DataTable.Clone() and DataTable.Clear() both methods are returning just the headers. But when I read the new set of data into the same datatable, the headers it seems are over written, maybe the DataTable gets re initialized.

2 Likes

Ok! now I understand the problem…

Can you use the Read Range activity without AddHeaders starting at A2?

If you need the columns to be called in a concrete way you can always change the name of the columns.

Regards,
Susana