Ways to store data in .NET

早过忘川 提交于 2019-12-18 13:38:29

问题


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 retrieved.

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


回答1:


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.




回答2:


An easy way would be to make use of XML.

Using XML in C# in the simplest way

Read/Write Xml document with FileStream




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/2709006/ways-to-store-data-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!