Game Development Reference
In-Depth Information
</book>
<book genre=”philosophy” publicationdate=”1991” ISBN=”1-861001-57-6”>
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
The following example shows how to load an XML file into a DataSet and then
retrieve and update node values.
using System;
using System.Data;
using System.Windows.Forms;
DataSet dataSet = new DataSet();
dataSet.ReadXml(@”C:\Books.xml”);
MessageBox.Show(“Row Count: “ + dataSet.Tables[“book”].Rows.Count.ToString());
MessageBox.Show(“First Author => Last Name: “ +
(string)dataSet.Tables[“author”].Rows[0][“last-name”]);
// Update the last name of the first author
dataSet.Tables[“author”].Rows[0][“last-name”] = “Wihlidal”;
// Persist the changes back out to the xml file
dataSet.WriteXml(@”C:\Books.xml”);
Potion Database Editor
The Companion Web site contains an example for this chapter that demonstrates
how to use a data reader to build a simple editor. The editor is for a fictitious role-
playing game, and it handles the database management of potions. You can add
new potions, modify the stats of existing potions, or delete potions from the data-
base. This editor could have been built using any number of the objects discussed
throughout this chapter but was done with a data reader because of personal pref-
erence. The editor uses a simple Access database file so that you do not have to
configure SQL Server to run this example.
Figure 24.1 shows the interface for the potion editor on the Companion Web site.
Search Nedrilad ::




Custom Search