Remove duplicate database error


#1

Hello,

I need to remove some duplicate raw from a data table and I use the following code:

dt=dt.DefaultView.ToTable(True,{“Column1”,“Column2”,“Column3”,“Column4”})

but I get the exception " A column named ‘Column4’ already belongs to this DataTable"

Someone knows how to fix this?

thank you


#2

Hi,
Is it possible to attach the xml, to check the error. Because I have verified it . It is working well.


#3

Hi @Siltra,

Refer this post

DataTable

Regards,
Arivu


#4

Can you try this.without curly braces

dt=dt.DefaultView.ToTable(True,“Column1”,“Column2”,“Column3”,“Column4”)


Duplicate rows in data table
#5

Thank you for your answer. I think I can to resolve it using dt=dt.DefaultView.ToTable(True) because I’m working with the entire data table.

The problem now is that I have two equal rows that differ only for one space and robot can’t recognize it.
There is a way to remove all spaces from the entire table?

Thank you again for your support


#6

:+1:


#7

you should not remove all the empty space, you need to remove at the end only
try like this
((From LineNo In dt.DefaultView.ToTable(True,"Product").Select().ToList() Select (From row In dt.Select Where row("Product").ToString.Trim=LineNo("Product").ToString.Trim Select row).ToList(0)).ToList()).CopyToDatatable()