hi, i just have a few weeks programming with vc# (2008) and i'm trying to build an application (winforms) and i have the following problem... i need my application to work with and without connection to the mssql database, this sounds like piece of cake for our friend DataSet right? i can persist the data as XML or binary until i can reach the database and the DataSet will magically sync; all without bothering the user. The problem is... the few books i have read just mention that logic like a fairy tale but dont give any practical example of how to do it, can you point me to one example/demo/whatever i can read or download of an application with (equal or) similar logic?
+1
A:
To serialize should be just this simple:
Binary.BinaryFormatter formatter = new Binary.BinaryFormatter();
DataSet ds = new DataSet();
// populate data set
using (FileStream fs = new FileStream("c:\\dataset.bin", FileMode.CreateNew))
{
ds.RemotingFormat = SerializationFormat.Binary;
formatter.Serialize(fs, ds);
}
to deserialize:
using (FileStream fs = new FileStream("c:\\dataset.bin", FileMode.Open))
{
formatter = new BinaryFormatter();
DataSet ds = (DataSet)formatter.Deserialize(stream);
}
(Roughly... not near compiler for proper testing)
Paul Sasik
2010-05-04 02:55:39
And if you want to serialize via XML: http://www.diranieh.com/NETSerialization/XMLSerialization.htm#Examples%20of%20XML%20Serialization
John Rasch
2010-05-04 03:09:31
A:
If you're using DataSet, you can just use DataSet.WriteXml and DataSet.ReadXml. Or am I missing something?
Matt Hamilton
2010-05-04 03:24:07