This row already belongs to another table This row already belongs to another table asp.net asp.net

This row already belongs to another table


As the error states, a DataRow instance is tied to its owning DataTable and cannot be added to another table.

Instead, use the ImportRow() method to make an actual copy of the row.


For Example

You need to create a new Row with the values from dr first. A DataRow can only belong to a single DataTable.

You can also use Add which takes an array of values:

myTable.Rows.Add(dr.ItemArray)

Or probably even better:

myTable.ImportRow(dr);

Link