Move DataRow to other DataTable

  • Thread starter Thread starter Darren
  • Start date Start date
D

Darren

I'm trying to move a row from one table to another. I get the error message that
the row already belongs to another table even though I have removed it from the table.
I'm trying to avoid recreating the row for performance reasons.

DataTable dataTable1 = dataTable2.Clone();

dataTable1.Rows.Remove(row);
dataTable2.Rows.Add(row);

TIA
 
Try putting an EndEdit after the Rows.Remove(row). This will commit
the changes to the DataTable.

It's odd; it seems like you should add it to the second datatable
before removing it from the first.

Robin S.
 
Ayon kay Darren:
I'm trying to move a row from one table to another. I get the error message that
the row already belongs to another table even though I have removed it from the table.
I'm trying to avoid recreating the row for performance reasons.

DataTable dataTable1 = dataTable2.Clone();

dataTable1.Rows.Remove(row);
dataTable2.Rows.Add(row);

TIA


try the ff.:

datatable2.ImportRow(row)
datatable1.Rows.Remove(row)

HTH
 
Hi Darren,
According to your description, I understand that you would like to move a
row from one table to another table.
If I misunderstand anything here, please don't hesitate to correct me.
Thanks.

You can use the following code to move the row from DataTable1 to DataTable2

DataTable dataTable2 = dataTable1.Clone();
//copy rowdata from table1 to table2
dataTable2.Rows.Add(row.ItemArray);
//remove rowdata from table1
dataTable1.Rows.Remove(row);

If there is anything unclear, please feel free to reply me and we are glad
to work with you.
Have a great day.
Best regards,
Wen Yuan
 
Hi Darren,

Just want to check if there is anything we can help with.
Please feel free to reply me here and we will follow up.

Happy New Year!
Sincerely,
Wen Yuan
 
Back
Top