开发者

Ways to store data in .NET

I am looking for ways to store data in a Windows Forms application in .NET. I want to make the input data of a system persistent, so when I close my program and open it again, the data is开发者_Python百科 retrieved.

Which ways of doing this exist besides creating a linked database? Examples are gladly appreciated.


There are dozens of different ways to store data. It completely depends on what data. Is it:

  • Just a couple of configuration values? Use the built-in Settings library.
  • Machine-wide configuration? Use the registry.
  • Transactional? Use a relational database.
  • Related but not transactional? Use a lightweight database like SQLite or SQLCE.
  • Structured but not related? Use XML or JSON files.
  • Somewhat structured and high in volume? Use a NoSQL solution like MongoDB.

And so on... there are different solutions for every storage requirement and many projects make use of more than one at a time.


An easy way would be to make use of XML.

Using XML in C# in the simplest way

Read/Write Xml document with FileStream


If your data is not mission critical (e.g. user preferences), you could just serialise your objects to file, and de-serialise them next time the app is loaded.


Examples? Do your homework yourself :)

Anyhow, possible ways are:

  • Registry.
  • Files. Like Microsoft Word does. Or like an ini file, like most games do for example for their settings
  • Databaase

Which makes sense depends on what the application DOES and other scenarios around it. A fast answer is not really possible without knowing more.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜