|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Move DataRow to other DataTableI'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. ------------------------------------ Show quote "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 Ayon kay Darren:
> I'm trying to move a row from one table to another. I get the error message that try the ff.:> 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 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 |
|||||||||||||||||||||||