Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataSet.Merge() and Deleted Rows
Message
De
14/08/2006 17:41:48
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
 
À
14/08/2006 16:04:00
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01145418
Message ID:
01145451
Vues:
27
>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,

I don't know for certain, but the order of the merge seems suspect to me. dsChanges has all changes (including deletes), so after merging it the rowstates will be Deleted and the Current row values will be gone. Then merging all changes back in would miss the the deleted rows because the Current rows are not there anymore.

Just a guess, really. It's after 5PM here and I turned off my brain about 30 minutes ago.

I don't know why it would be different depending on when you set the primary key, except that perhaps upon setting the primary key all rowstate information is reset.

To me, GetChanges, Merge, and RowState has always seemed to be a convoluted thing that never impressed me as able to stand the test of time. I figured that by now they would have come up with something a little more straightforward. Oh well.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform