PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Move DataRow to other DataTable

Reply

Move DataRow to other DataTable

 
Thread Tools Rate Thread
Old 22-12-2006, 06:34 PM   #1
Darren
Guest
 
Posts: n/a
Default Move DataRow to other DataTable


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
  Reply With Quote
Old 22-12-2006, 08:27 PM   #2
RobinS
Guest
 
Posts: n/a
Default Re: Move DataRow to other DataTable

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



  Reply With Quote
Old 23-12-2006, 09:13 AM   #3
diego
Guest
 
Posts: n/a
Default Re: Move DataRow to other DataTable


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

  Reply With Quote
Old 25-12-2006, 09:03 AM   #4
WenYuan Wang
Guest
 
Posts: n/a
Default RE: Move DataRow to other DataTable

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

  Reply With Quote
Old 29-12-2006, 07:34 AM   #5
WenYuan Wang
Guest
 
Posts: n/a
Default RE: Move DataRow to other DataTable

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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off