Copy rows from one DataSet to another

  • Thread starter Thread starter Dennis Davitt
  • Start date Start date
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!
 
void CopyRows(DataTable oSrcDataTable, DataTable oDstDataTable)
{
foreach (DataRow oDataRow in oSrcDataTable.Rows)
oDstDataTable.ImportRow(oDataRow);
}

Tony
 
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!
 
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!
 
Back
Top