When you try to add a DataRow from one table to another, you may encounter the following error message:
"This row already belongs to another table."
This error message appears if you try to add (copy) a DataRow from table1 to table2, for example, with the following C# code:
table2.Rows.Add(row);
where row is a DataRow object from table1.
To successfully copy the row, you'll need to use ImportRow() method:
table2.ImportRow(row);
Don't forget to define a proper value of column number for table2 first or no data will be displayed if you bind table2 with a gridview, for example.
|