簡體   English   中英

Visual C#2008數據庫應用程序示例

[英]visual c# 2008 database application examples

我只有幾周的時間使用vc#(2008)進行編程,而我正在嘗試構建一個應用程序(winforms),但是我遇到了以下問題...我需要我的應用程序可以在不連接mssql數據庫的情況下工作,對於我們的朋友DataSet來說聽起來像小菜一碟,對嗎? 我可以將數據保留為XML或二進制格式,直到可以訪問數據庫並且DataSet神奇地同步為止; 所有這些都不會打擾用戶。 問題是...我讀過的幾本書只是提到邏輯,就像童話故事一樣,但是沒有給出任何實際的示例,您可以指出一個示例/演示/我可以閱讀或下載的任何內容。具有(相等或)相似邏輯的應用程序?

要序列化應該很簡單:

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);
    }

反序列化:

    using (FileStream fs = new FileStream("c:\\dataset.bin", FileMode.Open)) 
    {
        formatter = new BinaryFormatter();
        DataSet ds = (DataSet)formatter.Deserialize(stream);

    }

(大約...不靠近編譯器以進行正確的測試)

如果使用的是DataSet,則只需使用DataSet.WriteXmlDataSet.ReadXml 還是我錯過了什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM