[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

readxml serialize/deserialize dataset

MWT

1/23/2008 12:55:00 AM

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

1 Answer

John Saunders [MVP]

1/23/2008 1:06:00 AM

0

"MWT" <MWT@discussions.microsoft.com> wrote in message
news:388BFB94-1978-4D87-AF81-C0620ABAE657@microsoft.com...
> 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/55h....
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer