Skip to content
Advertisement

remove duplicate column name before add it on DataTable

Here is my code :

My problem is when the loop gets here :

res.Results.Columns.Add(new DataColumn(reader.GetName(i)));

Everything works fine as long as I use only one table. When I use two or more tables, I get an error message “column [i] already exists”.

Exemple :

=> error will be : “column ‘Name’ already exist”, because it is read twice (one per table).

How can i keep only one column if they have the same name ?

Advertisement

Answer

do you need both tables data?

if not – return only first table data

if yes – list all required fields in select, and give them unique names:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement