PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Move DataRow to other DataTable
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Move DataRow to other DataTable
![]() |
Move DataRow to other DataTable |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. ------------------------------------ "Darren" <Darren@nospam.nospam> wrote in message news:uzZBuhfJHHA.4068@TK2MSFTNGP03.phx.gbl... > 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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

