开发者

visual c# 2008 database application examples

开发者 https://www.devze.com 2022-12-29 15:36 出处:网络
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 t

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 开发者_Go百科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?


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)


If you're using DataSet, you can just use DataSet.WriteXml and DataSet.ReadXml. Or am I missing something?

0

精彩评论

暂无评论...
验证码 换一张
取 消