This row already belongs to another table
April 6, 2011 3 Comments
Occurs when you copy a DataRow from one DataTable to another throwing an ArgumentException
The error occurs because the same datarow object could not be added to different datatables.The best solution is using
the DataTable.ImportRow method which creates an exact copy of the row and adds it to the other table. However, in order to use this function
, both tables should have the same schema which is achieved using a method call to DataTable.Clone() to copy shema only or DataTable.Copy() to copy both data and schema. The code below shows how to do this:
Dim dt As New DataTable 'dt = FillRowFromDataBase Dim dtClone As DataTable = dt.Clone For Each row As DataRow In dt.Rows dtClone.ImportRow(row)Next

Welcome to Ali's blog, A computer engineer & scientist specialized in software development and algorithms.
Recent Comments