Maintaining column headers after clearing Datatable

datatable

#1

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?


#2

Hello @pearlb,

Have you tried using DataTable.Clone method?

CloneDataTable.xaml (11.7 KB)

https://msdn.microsoft.com/es-es/library/system.data.datatable.clone(v=vs.110).aspx

Regards,
Susana


#3

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).


#4

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.


#5

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