Copying a row into another row

  • Thread starter Thread starter Nijazi Halimaji
  • Start date Start date
N

Nijazi Halimaji

Hi everybody

I try to copy a row into another row. trying this will cause an error : "The
row already belongs to another table"

this is my code:
dsnotSent.Tables(0).Rows.Add(ds.tables(0).rows(0))



How to handle this?



Thanks alot



Nijazi Halimaji
 
Can I get the answer to this in English? I'm having a similar problem.

Thank-you,
Barbara Alderton
 
Barbara,

I at least tried to give the answer in English on that German question.

However, the problem (not really) with most AdoNet objects is that the
parent holds forever a collection and the child points back to the parent.
(And because that there can be only one parent, you cannot use it in two
parents)

Extra is for the datarow that the schema from a datarow has to be correct,
so what you can do is clone the table.

dim dtclone as datatable = dt.clone
'than make a reference to the row you want to place in another table
dim a as datarow = dt.rows(1) 'for the second row
than remove it from the original table
dt.rows.removeat(1)
'than add it to the cloned table
dtclone.add(a)

I hope this helps.

Cor
 
Barbara,

Here's a much simpler way:

dsnotSent.Tables(0).Rows.Add(ds.tables(0).rows(0).ItemArray)

or, an even faster way:

dsnotSent.Tables(0).LoadDataRow(ds.tables(0).rows(0)..ItemArray, True)

Hope this helps
Ad.
 
Adrian,

In my opinion does what you show not move however make a shallow copy of the
objects in a new datarow.

There are more side effects to concern about, however as that is intended,
than there is no problem.

Just my thought,

Cor
 
Back
Top