Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRow belongs to another table.... 2

Status
Not open for further replies.

Sarmx

Programmer
Jun 16, 2004
12
NL
Dear Friends,

I Have two DataTables, dt1 and dt2. I Want to add
a Row From dt1 to dt2 this is my code:

Code:
Dim dRow As DataRow
dRow = dt1.Rows(IndexOfTargetRow)

 dRow.Delete()
 dRow.AcceptChanges()
'Or instead of two lines above: dt1.Rows.Remove(dRow)

If dRow.RowState = DataRowState.Detached Then
        dt2.Rows.Add(dRow)
end if

Even when RowState shows that dRow is detached,
when the line dt2.Rows.Add(dRow) is executed i get
an error which says: "This row already belongs to another table"

can somebody tell me why?? or how can i add a DataRow
from one DataTable to another???can i make a copy from
a DataRow???

Thanks For any help

 
Try this
Code:
Dim FromRow As DataRow = dt1.Rows(IndexOfTargetRow)
Dim ToRow As DataRow = dt2.NewRow()
ToRow.ItemArray = FromRow.ItemArray
dt2.Rows.Add(ToRow)
'Then add code if you wish to delete the row from dt1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top