Sunday, December 7, 2008

DataSet.WriteXml

Let's talk about .NET Framework (Compact Framework to be more specific) .... again... After spent several hours trying to put my XML file control class to work properly i finnally had some success. When i saw the methods WriteXml and ReadXml for DataSet object i said to myself: "Zeca take a note here... this is pretty usefull!"... only for after a few minutes of coding bash to find out that it didn't quite work like i wanted... things is quite simple to be explained, at least the problem, i check if file exists (Sistem.IO.File.Exists(filepath) - or similar), if not, create a new one with default data on it, then return the data, if file exists, use ReadXML on DataSet and get the data... well ... this works pretty well, ok, now i loaded data into some forms (a settings form) then modify some and exit the form to main menu, when i exit i store the changes on DataSet, and do a WriteXml at the end, simple right? Well it works .... until you do the drill a second time.... it reads correctly, it calls WriteXml at exit, it seems to save the changes .... but it doesn't! Now my solution: Don't use the same DataSet! Create a new one, and yes i tried commitChanges methods before trying this solution... in the end this was the only thing that work. I don't know why this happens, anyway it could be a file open mode problem - when reading the information the file is openned in read mode, and later when writing on it, DataSet.WriteXML uses the same file handler to do the job... failing silently... If anyone had the same problem or know what i was/am doing wrong please fell free to comment it out. Thanks in advance. PS: I really start to hate ALL object oriented languages - not all object-able languages

No comments: