readxml serialize/deserialize dataset

  • Thread starter Thread starter MWT
  • Start date Start date
M

MWT

Serialize dataset:

MemoryStream stream = new MemoryStream();
dataset.WriteXml(stream, XmlWriteMode.DiffGram );
stream.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(stream);
datasetstring = sr.ReadToEnd();

this is the datastring:

“<diffgr:diffgram xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"
xmlns:diffgr=\"urn:schemas-microsoft-com:xml-diffgram-v1\">\r\n
<NewDataSet>\r\n <Table1 diffgr:id=\"Table11\" msdata:rowOrder=\"0\"
diffgr:hasChanges=\"modified\">\r\n <ID>1</ID>\r\n
<NUMMER>1001</NUMMER>\r\n <ACHTERNAAM>Changed</ACHTERNAAM>\r\n
</Table1>\r\n </NewDataSet>\r\n <diffgr:before>\r\n <Table1
diffgr:id=\"Table11\" msdata:rowOrder=\"0\">\r\n <ID>1</ID>\r\n
<NUMMER>1001</NUMMER>\r\n <ACHTERNAAM>BlaBla</ACHTERNAAM>\r\n
</Table1>\r\n </diffgr:before>\r\n</diffgr:diffgram>"

Now deserialize:
//--deserialize
StringReader stringReader = new
StringReader(datasetstring);
DataSet ds = new DataSet();
ds.ReadXml(stringReader,XmlReadMode.DiffGram );

Now dataset ds is empty, what am I doing wrong ?
I use VS2008
 
MWT said:
Serialize dataset:

MemoryStream stream = new MemoryStream();
dataset.WriteXml(stream, XmlWriteMode.DiffGram );
stream.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(stream);
datasetstring = sr.ReadToEnd();

this is the datastring:

"<diffgr:diffgram xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"
xmlns:diffgr=\"urn:schemas-microsoft-com:xml-diffgram-v1\">\r\n
<NewDataSet>\r\n <Table1 diffgr:id=\"Table11\" msdata:rowOrder=\"0\"
diffgr:hasChanges=\"modified\">\r\n <ID>1</ID>\r\n
<NUMMER>1001</NUMMER>\r\n <ACHTERNAAM>Changed</ACHTERNAAM>\r\n
</Table1>\r\n </NewDataSet>\r\n <diffgr:before>\r\n <Table1
diffgr:id=\"Table11\" msdata:rowOrder=\"0\">\r\n <ID>1</ID>\r\n
<NUMMER>1001</NUMMER>\r\n <ACHTERNAAM>BlaBla</ACHTERNAAM>\r\n
</Table1>\r\n </diffgr:before>\r\n</diffgr:diffgram>"

Now deserialize:
//--deserialize
StringReader stringReader = new
StringReader(datasetstring);
DataSet ds = new DataSet();
ds.ReadXml(stringReader,XmlReadMode.DiffGram );

Now dataset ds is empty, what am I doing wrong ?
I use VS2008

Have you tried to do ds.AcceptChanges()? See
http://msdn2.microsoft.com/en-us/library/55hehd8c.aspx.
 
Back
Top