"This row already belongs to another table" - Annoying, to say the least!
The workaround, simple but elusive.
public DataTable CopyDataTable(DataTable dtSource, int iRowsNeeded)
{
if (dtSource.Rows.Count > iRowsNeeded)
{
// cloned to get the structure of source
DataTable dtDestination = dtSource.Clone();
for (int i = 0; i < iRowsNeeded; i++)
{
dtDestination.ImportRow(dtSource.Rows[i]);
}
return dtDestination;
}
else
return dtSource;
}
Happy Coding!
0 comments on "Copy DataRows from one DataTable to Another"
Subscribe in a Reader
Post a Comment