Copy rows from one DataSet to another

D

Dennis Davitt

When trying to "copy" rows from one dataSet to another I get an exception
that say: "This Row already belongs to another table".

Any ways around this?

I am trying to take a DS from a WebService and initially the RowState is
unchanged. I went through the rows to fool the row state by iterating
through the datarowcollection and setting dr[0] = dr[0]; however this
changes the state to modified and the DataAdapter calls the Update command.
I need to call the INSERT command because all those rows retrieved from the
dataSet "MUST" be inserted into the SQL table.

Any help would be greatly appreciated. Thanks!
 
T

Tony

void CopyRows(DataTable oSrcDataTable, DataTable oDstDataTable)
{
foreach (DataRow oDataRow in oSrcDataTable.Rows)
oDstDataTable.ImportRow(oDataRow);
}

Tony
 
D

Dennis Davitt

Tony,

The reason I am trying to copy from 1 dataSet to another is to have the
RowState change.
When doing an Import, it copies the state of the DataSet which in my
scenario, all the rows states are "Unchanged".
I want to change the rowstate so that I can use the DataAdapter's method to
update my SQL database, however, I need to INSERT records and the
dataAdapter only inserts rows that have a state of "ADDED"!!! Any help in
getting this accomplished?

Thanks!

Tony said:
void CopyRows(DataTable oSrcDataTable, DataTable oDstDataTable)
{
foreach (DataRow oDataRow in oSrcDataTable.Rows)
oDstDataTable.ImportRow(oDataRow);
}

Tony

Dennis Davitt said:
When trying to "copy" rows from one dataSet to another I get an exception
that say: "This Row already belongs to another table".

Any ways around this?

I am trying to take a DS from a WebService and initially the RowState is
unchanged. I went through the rows to fool the row state by iterating
through the datarowcollection and setting dr[0] = dr[0]; however this
changes the state to modified and the DataAdapter calls the Update command.
I need to call the INSERT command because all those rows retrieved from the
dataSet "MUST" be inserted into the SQL table.

Any help would be greatly appreciated. Thanks!
 
M

md

Look at DataTable.BeginLoadData, LoadDataRow, and EndLoadData

Dennis Davitt said:
Tony,

The reason I am trying to copy from 1 dataSet to another is to have the
RowState change.
When doing an Import, it copies the state of the DataSet which in my
scenario, all the rows states are "Unchanged".
I want to change the rowstate so that I can use the DataAdapter's method to
update my SQL database, however, I need to INSERT records and the
dataAdapter only inserts rows that have a state of "ADDED"!!! Any help in
getting this accomplished?

Thanks!

Tony said:
void CopyRows(DataTable oSrcDataTable, DataTable oDstDataTable)
{
foreach (DataRow oDataRow in oSrcDataTable.Rows)
oDstDataTable.ImportRow(oDataRow);
}

Tony

Dennis Davitt said:
When trying to "copy" rows from one dataSet to another I get an exception
that say: "This Row already belongs to another table".

Any ways around this?

I am trying to take a DS from a WebService and initially the RowState is
unchanged. I went through the rows to fool the row state by iterating
through the datarowcollection and setting dr[0] = dr[0]; however this
changes the state to modified and the DataAdapter calls the Update command.
I need to call the INSERT command because all those rows retrieved
from
the
dataSet "MUST" be inserted into the SQL table.

Any help would be greatly appreciated. Thanks!
 

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