Clean DataTable Structure

Hello,
I’ve a For Each Loop and every time at the start of the for each loop I’ve to completely completely the data table, in order to erase the content and the headers.
I’ve tried to assign Nothing, or New DataTable() or build an empty data table but I got every time the same error: DuplicateNameException.

I’ve read that a possible solution is to uncheck the AddHeaders option into Read Range, but I need to work with column header, so I can’t avoid them.
So, what is a possible solution?

Thanks!

Have you tried the Clear Data Table activity?

@kaderms, I’ve got the same error.

Okay. Can you share the below screenshots?

  1. sequence of your activities
  2. variables pane
  3. Output console once your process stops with this error

Fine
may i know at which activity we are getting this error

Cheers @fe.cuozzo

1 Like

(add header is selected and I’ve removed the assign activity)

I’m getting the error in the Excel Application Scope. I’m reading multiple Excel file and I’ve to add columns and data.
So, at the end, I’ve a Clear Data Table on inputDT.

Hi @fe.cuozzo,

DuplicateNameException is thrown when there’s duplicate database object name is encountered during reading of the data.
So check the column names (Header), if there’re 2 columns with the same header name then it’ll throw this type of exception.

Hi @samir,
At the end of the “for each loop” there’s a Clear Data Table, which can delete schema and data from the inputDT. So, I’ve to rewrite on the clean inputDT and I got the error…

Thanks

Yes @fe.cuozzo , but I’m talking about Read Range only, it won’t allow Read range with 2 or more columns having same header names.
Column Names (headers) should be unique.

And so, @samir, how can I re-use the same inputDT for several excel files with different headers?
Thanks

There is no issue with your inputDt
issue is the file headers are not unique when you are reading the excel file in loop there is a file which contains the same column names

@fe.cuozzo,

I’m saying is your data containing 2 columns with same headers…?
As i shown in below shot.

image

Ok, so the Clear Data Table is not for my purpose.
Alternatively, I’ve declared a new istance of the inputDT, by using the Assign Activity, between the two Excel Application Scope activities. The inputDT is empty, without any headers or values.
But, I got the same error.

Dude @fe.cuozzo,

All i’m saying is your error is for read range activity you can see that in your screenshot only,
From the error message you can see that … Message : A column named ‘LOW REF’ already belongs to the table…
MEANS… there 2 columns with same name ‘LOW REF’ which is against standard naming convention for a table.
‘LOW REF’ already belongs to the table —> here, compiler doesn’t meant ‘LOW REF’ already belongs to the previous dataTable. It meant you’re having data with minimum 2 columns having same headers ‘LOW REF’, As i shown in my previous post.
image

You can use clear data table where you need to BUT here 1 datatable Columns should have unique headers

2 Likes