Donate

Column 'column_name' Already Belongs To Another DataTable in C#

In a scenario where I added columns using AddRange(), I encountered an error as specified by the title.
Here's the C# code:
table1.Columns.AddRange(new DataColumn[] { col1, col2, col3 });  
table2.Columns.AddRange(new DataColumn[] { col1, col2, col3 });
Where col1, col2, col3 are DataColumn objects.
What I did was to initialize columns in the addrange method. But there are other solutions in the forums.
table1.Columns.AddRange(new DataColumn[] { new DataColumn("ID"), new DataColumn("WEB ID"), new DataColumn("URL") });  
table2.Columns.AddRange(new DataColumn[] { new DataColumn("ID"), new DataColumn("WEB ID"), new DataColumn("URL") });

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.