简体   繁体   English

在WinForms应用程序中存储数据

[英]Storing data in WinForms applications

This is probably a very basic question, but I'm in the process of making a Windows Forms based application, which will involve a hefty amount of data storage. 这可能是一个非常基本的问题,但我正在制作基于Windows窗体的应用程序,这将涉及大量的数据存储。 It will essentially be a sports simulator where there'll be hundreds of teams, with thousands of players. 它本质上是一个运动模拟器,那里将有数百个球队,有数千名球员。

So I need to figure out the best way to store this data. 所以我需要弄清楚存储这些数据的最佳方法。 Windows Forms is relatively new to me as I've been mostly working with ASP.NET, but I've come up with the following ideas: Windows Forms对我来说相对较新,因为我主要使用ASP.NET,但我想出了以下想法:

  1. Compact SQL database in the program directory 程序目录中的Compact SQL数据库
  2. Files containing the serializable objects. 包含可序列化对象的文件。

Are there any other solutions out there that may be better? 还有其他解决方案可能更好吗? Or which of these should I pick? 或者我应该选择哪一个?

Your requirements are extremely vague, but in general stay away from serialization for any kind of persistent data store. 您的要求非常模糊,但总体上远离任何类型的持久性数据存储的序列化。

If your data is relational (it has internal structure, such as "teams must contain players" or "a player can be a member of only one team") then I suggest a relational DBMS such as SQL Server Compact Edition or SQLite. 如果您的数据是关系型的(它具有内部结构,例如“团队必须包含玩家”或“玩家只能是一个团队的成员”),那么我建议使用关系型DBMS,例如SQL Server Compact Edition或SQLite。

If your data is not relational, I suggest a key/value store like RavenDB . 如果您的数据不是关系数据,我建议像RavenDB这样的键/值存储。

Also, do not put data in the program directory; 另外,不要将数据放在程序目录中; it may not be writable by the user. 它可能不是用户可写的。 Store data in the user directory. 将数据存储在用户目录中。

If you have any need to execute queries against the data, I would stay away from serializing it in a proprietary format. 如果您需要对数据执行查询,我将远离以专有格式对其进行序列化。

If there is only one user, then you could do something simple like an Access MDB via the JET drivers, SQLLite or NoSQL. 如果只有一个用户,那么你可以通过JET驱动程序,SQLLite或NoSQL做一些简单的访问MDB。

If there are going to be multiple concurrent users, you'll almost certainly need to look at a 'server' based SQL - eg SQL Express (although note the DB Size limitations), MySQL etc. 如果将有多个并发用户,您几乎肯定需要查看基于“服务器”的SQL - 例如SQL Express(尽管注意数据库大小限制),MySQL等。

Could use an .MDB Access database to store the data. 可以使用.MDB Access数据库来存储数据。 Not as reliable in my experience as SQLite. 我的经验不如SQLite那么可靠。

Also, you don't mention if you need to persist these data after the form closes? 另外,您没有提到在表单关闭后是否需要保留这些数据? If you don't you may just want to use in memory DataSet's (or DataTables) to keep the data quickly accessable. 如果不这样做,您可能只想在内存中使用DataSet(或DataTables)来保持数据的快速访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM