Of Dataset.GetChanges and Diffgrams

The state of the change has a bearing on how you should examine the changes in a dataset.

Q: Why does Dataset.GetChanges() return an empty dataset? Examine the following code: The dataset stored in ChangedDoc.xml is empty. Why?

ds.ReadXml("http://localhost:400/TMSEProto/Proposal.xml");
ds.AcceptChanges();
ds.Tables["LineDetail"].Rows[2].Delete();

DataSet ds1;
ds1 = ds.GetChanges(DataRowState.Deleted);
ds1.WriteXmlSchema("c:\\ChangedSchema.xml");
ds1.WriteXml("c:\\ChangedDoc.xml");
// ChangedDoc.xml is empty :-(

A: It’s all in the Diffgrams.

There is more than one WriteXml method.  DataSet.GetChanges() does return the deleted rows. But, they are marked as deleted, so they are hidden from normal view.  To write the deleted rows, you need to serialize the dataset asa diffgram:

WriteXml( XmlWriteMode.DiffGram );

This will serialize both the original and current values, and will therefore include the deleted rows. The deleted rows will be marked as deleted. In fact, every modified row will show two versions: the original and the modified version.



Published 03 May 2004 08:52 PM by wwagner
Filed under: ,
Ads by Lake Quincy Media

Comments

No Comments

Search

Go

Blog Group Links

Nascar style badges