datatable

D

daveL

hello
i have a Datatable i use for a datagridview
when a user selects a row, i return the row to the
calling window (doubleclickevent)

in the calling method i want to set the datarow to a tmp datatable to use
with sqldataadapter updates, inserts
but when i try to add the row to the tmp table
derived from the same physical table in sql schema

i get a error row already belongs to a datatable
is there a way to change the owning table in the datarow
or do i have to create a new datarow from the tmp table
and copy the columns from the Returnd DataRow

Thanks
DaveL
 
A

Alberto Poblacion

daveL said:
i get a error row already belongs to a datatable
is there a way to change the owning table in the datarow
or do i have to create a new datarow from the tmp table
and copy the columns from the Returnd DataRow

Yes, that's what you have to do, but there is an easy way to do it in a
single line:

theTmpTable.Rows.Add(theDataRow.ItemArray);

"ItemArray" extracts an array of objects with the values of the columns.
That array is then used as an argument for the overload of the Add method
that takes an object[].
 
D

DaveL

thanks alot , much appriciated
DaveL

Alberto Poblacion said:
daveL said:
i get a error row already belongs to a datatable
is there a way to change the owning table in the datarow
or do i have to create a new datarow from the tmp table
and copy the columns from the Returnd DataRow

Yes, that's what you have to do, but there is an easy way to do it in a
single line:

theTmpTable.Rows.Add(theDataRow.ItemArray);

"ItemArray" extracts an array of objects with the values of the columns.
That array is then used as an argument for the overload of the Add method
that takes an object[].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top