<p>I've recently taken up learning some C# and wrote a Yahtzee clone.  My next step (now that the game logic is in place and functioning correctly) is to integrate some method of keeping stats across all the games played.</p>

<p>My question is this, how should I go about storing this information?  My first thought would be to use a database and I have a feeling that's the answer I'll get... if that's the case, can you point me to a good resource for creating and accessing a database from a C# application?</p>

<hr>

<p>Storing in an XML file actually makes more sense to me, but I thought if I suggested that I'd get torn apart ;).  I'm used to building web applications and for those, text files are generally frowned upon.</p>

<p>So, going with an XML file, what classes should I be looking at that would allow for easy manipulation?</p>

[{'answer_id': 20086, 'author': 'palmsey', 'author_id': 521, 'author_profile': 'https://Stackoverflow.com/users/521', 'pm_score': 3, 'selected': False, 'text': '<p>A database may be overkill - have you thought about just storing the scores in a file?</p>\n\n<p>If you decide to go with a database, you might consider <a href="http://sqlite.org/" rel="nofollow noreferrer">SQLite</a>, which you can distribute just like a file. There\'s an open source .NET provider - <a href="http://sqlite.phxsoftware.com/" rel="nofollow noreferrer">System.Data.SQLite</a> - that includes everything you need to get started.</p>\n\n<p>Accessing and reading from a database in .NET is quite easy - take a look at <a href="https://stackoverflow.com/questions/930/how-do-i-connect-to-a-database-and-loop-over-a-recordset-in-c">this question</a> for sample code.</p>\n'}, {'answer_id': 20087, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 4, 'selected': False, 'text': "<p>A database would probably be overkill for something like this - start with storing your information in an XML doc (or series of XML docs, if there's a lot of data).  You get all that nifty XCopy deployment stuff, you can still use LINQ, and it would be a smooth transition to a database if you decided later you really needed performant relational query logic.</p>\n"}, {'answer_id': 20089, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 2, 'selected': False, 'text': "<p>I don't know if a database is necessarily what you want. That may be overkill for storing stats for a simple game like that. Databases are good; but you should not automatically use one in every situation (I'm assuming that this is a client application, not an online game).</p>\n\n<p>Personally, for a game that exists only on the user's computer, I would just store the stats in a file (XML or binary - choice depends on whether you want it to be human-readable or not).</p>\n"}, {'answer_id': 20095, 'author': 'Jon Dewees', 'author_id': 1365, 'author_profile': 'https://Stackoverflow.com/users/1365', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.microsoft.com/sql/editions/express/default.mspx" rel="nofollow noreferrer">SQL Express</a> from MS is a great free, lightweight version of their SQL Server database. You could try that if you go the DB route.</p>\n\n<p>Alternatively, you could simply create datasets within the application and serialize them to xml, or you could use something like the newly minted <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework" rel="nofollow noreferrer">Entity Framework</a> that shipped with .NET 3.5 SP1</p>\n'}, {'answer_id': 20117, 'author': 'Skizz', 'author_id': 1898, 'author_profile': 'https://Stackoverflow.com/users/1898', 'pm_score': 1, 'selected': False, 'text': '<p>You can either use the <code>System::Xml</code> namespace or the <code>System::Data</code> namespace. The first gives you raw XML, the latter gives you a handy wrapper to the XML.</p>\n'}, {'answer_id': 20130, 'author': 'Brian Ensink', 'author_id': 1254, 'author_profile': 'https://Stackoverflow.com/users/1254', 'pm_score': 5, 'selected': True, 'text': '<p>Here is one idea: use Xml Serialization.  Design your GameStats data structure and optionally use Xml attributes to influence the schema as you like.  I like to use this method for small data sets because its quick and easy and all I need to do is design and manipulate the data structure.</p>\n\n<pre><code>\nusing (FileStream fs = new FileStream(....))\n{\n    // Read in stats\n    XmlSerializer xs = new XmlSerializer(typeof(GameStats));\n    GameStats stats = (GameStats)xs.Deserialize(fs);\n\n    // Manipulate stats here ...\n\n    // Write out game stats\n    XmlSerializer xs = new XmlSerializer(typeof(GameStats));\n    xs.Serialize(fs, stats);\n\n    fs.Close();\n}\n</code></pre>\n'}, {'answer_id': 20140, 'author': 'Dale Ragan', 'author_id': 1117, 'author_profile': 'https://Stackoverflow.com/users/1117', 'pm_score': 1, 'selected': False, 'text': '<p>I would recommend just using a database.  I would recommend using LINQ or an ORM tool to interact with the database.  For learning LINQ, I would take a look at Scott Guthrie\'s posts.  I think there are 9 of them all together.  I linked part 1 below.  If you want to go with an ORM tool, say nhibernate, then I would recommend checking out the Summer of nHibernate screencasts.  They are a really good learning resource for nhibernate.</p>\n\n<p>I disagree with using XML.  With reporting stats on a lot of data, you can\'t beat using a relational database.  Yeah, XML is lightweight, but there are a lot of choices for light weight relational databases also, besides going with a full blown service based implementation.  (i.e. <a href="http://www.microsoft.com/sql/editions/compact/default.mspx" rel="nofollow noreferrer">SQL Server Compact</a>, <a href="http://www.sqlite.org/" rel="nofollow noreferrer">SQLite</a>, etc...)</p>\n\n<ul>\n<li><a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" rel="nofollow noreferrer">Scott Guthrie on LINQ</a></li>\n<li><a href="http://www.summerofnhibernate.com/" rel="nofollow noreferrer">Summer of nHibernate</a></li>\n</ul>\n'}, {'answer_id': 20144, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d recommend saving your data in simple POCOs and either serializing them to xml or a binary file, like Brian did above.</p>\n\n<p>If you\'re hot for a database, I\'d suggest <a href="http://www.microsoft.com/sql/editions/compact/default.mspx" rel="nofollow noreferrer">Sql Server Compact Edition</a>, or <a href="http://www.vistadb.net/" rel="nofollow noreferrer">VistaDB</a>.  Both are hosted inproc within your application.</p>\n'}, {'answer_id': 20209, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 1, 'selected': False, 'text': '<p>For this situation, the <code>[Serializable]</code> attribute on a nicely modelled <code>Stats</code> class and <code>XmlSerializer</code> are the way to go, IMO.</p>\n'}]
['https://Stackoverflow.com/questions/20061', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/271/']