I have a problem with my asp.net website, I am trying to copy a data row from one data table to another data table, but every time I am trying to do this i am getting an error:
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);