Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataSet.Merge() and Deleted Rows
Message
From
14/08/2006 16:04:00
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
DataSet.Merge() and Deleted Rows
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01145418
Message ID:
01145418
Views:
128
Anybody run into this before? I think it's a bug.

I'm trying to use the DataSet.Merge() method with Deleted rows. I'm using Typed DataSets (although I'm not sure if this makes a difference or not ... might need to play around with it more). Since I don't normally use the PrimaryKey property with my Typed DataSets, in order to use the Merge, I have to set the PrimaryKey columns for each DataTable. OK, no problem. The weird thing is, it appears that *where* I define the PrimaryKey seems to determine whether or not the Deleted rows merge correctly.

If I set the PrimaryKey properties for the tables *after* I have gotten the data, the DataSet with the Deleted rows is merged correctly.

If I set the PrimaryKey properties for the tables *before* I get the data, the Deleted rows are merged into the DataSet, but they are added on instead of deleting the existing row.

An example:
I made a copy of my Personnel DataSet, I then made changes in the Personnel DataSet and then merged them back to the copy:
dsCopy = (MyPersonnelDataSet)dsPersonnel.Copy();

// change a row in the Personnel table
dsPersonnel.Personnel[0]["userkey"] = 0;

// delete a row in the PhoneNumber table
dsPersonnel.PhoneNumber[0].Delete();

// add a row to the PhoneNumber table
DataRow row;
row = dsPersonnel.PhoneNumber.NewRow();
row["phonenumberkey"] = 0;
row["phone"] = "666";
dsPersonnel.PhoneNumber.Rows.Add(row);

dsChanged = (MyPersonnelDataSet)dsPersonnel.GetChanges();
dsDeleted = (MyPersonnelDataSet)dsPersonnel.GetChanges(DataRowState.Deleted);

// Merge the changes to dsPersonnel into dsCopy
dsCopy.Merge(dsDeleted);
dsCopy.Merge(dsChanged);
What happens is that the row that was deleted is not matched to the original row in the dsCopy dataset, so that I end up with two rows for the same data, one is unchanged and one is deleted ... what *should* happen is that there should only be one deleted row.

Am I hallucinating? <g>

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Next
Reply
Map
View

Click here to load this message in the networking platform