DataSet.Merge()

  • Thread starter Thread starter Timothy Parez
  • Start date Start date
T

Timothy Parez

Hi,

If I have an empty DataSet and a DataSet with data in it

and I do

EmptyDataSet.Merge(FullDataSet)

Then all the rows from FullDataSet get added to EmptyDataSet right?
But why does the rowstate not change to added or changed or something ?

Because I really need it to have a added or change rowstate


Thnx
Timothy.
 
Hello,

the Merge method works as documented, because it is used to incorporated
new/modfied data into the original dataset. Have a lock for more details
into the MSDN.
Try the Copy method, which produces a copy of schema and data. Because your
target dataset is empty, no data gets overwritten.
 
Copy also preserves the rowstate when copying the rows from one dataset to
another dataset.

One solution for this is to do the following.

destDataTable.BeginLoadData();
foreach (DataRow sourceRow in sourceDataTable.Rows) {
if (sourceRow.RowState != DataRowState.Deleted) { //Deleted rows will
not be added to the destination dataset.
destDataTable.LoadDataRow(sourceRow.ItemArray, false); }
}
destDataTable.EndLoadData();

The second parameter to LoadDataRow indicates whether AcceptChanges should
be called after adding the row. Since we want the rows to be in Added state,
the parameter is false.

HTH,
Ravi
 
Back
Top