Using XML to Design a DataSet


Using XML to Design a DataSet

The Visual Studio IDE includes a feature called the Data Designer that is available only when working on projects that target the desktop .NET Framework. The Data Designer is a powerful graphical utility that makes it easy to design a DataSet 's schema and populate it with data. The Data Designer can spit out code for you, which spares the developer from having to programmatically build DataSet s and populate them. Unfortunately, this tool is not available when working with the .NET Compact Framework.

If you don't want to write code in C# or Visual Basic to set up your DataSet , you can instead describe your DataSet with XML schema. You also write XML to populate your DataSet with tables. The information previously presented in this chapter should give you enough knowledge to start with one of the samples included with this book and alter it to suit your needs. When you need a DataSet , simply create a DataSet , and call ReadXml() or ReadXmlSchema() , depending on whether you only want to load in schema.

Schema Editing with the IDE

If you want to use XML to edit data that will be loaded into a DataSet , you can use the XML editor in the Visual Studio IDE. The XML editor is a convenient , graphical way to edit XML data.

The easiest way to use the XML editor is to open an existing XML file that has the schema already set up the way you want it. If you create a new XML file in the Visual Studio IDE, by default it contains no elements, and the visual editor will not start. If you start with an existing XML file, then you can use the GUI to delete all of the old tables, set up a schema, and insert data as you wish.

Figure 8.1 shows the XML editor immediately after opening the file SampleDataSet.xml . This file is in the directory \SampleApplications\Chapter8 . As you can see, when you first open an XML file, you see only the XML text.

Figure 8.1. When SampleDataSet.xml is first opened, the XML editor shows the XML code.

graphics/08fig01.jpg

To view the XML data in a graphical form, put the mouse over the editor, right-click, and select View Data. Figure 8.2 shows the result. All of the DataTable s are on the left side. Click on a DataTable to select it, and you will be able to view the rows and columns on the right side. You can edit the values, delete rows, and insert rows by clicking on the bottom row and inserting your data.

Figure 8.2. The XML editor can also show a data view.

graphics/08fig02.jpg

If the XML you loaded is somehow invalid, then trying to view the XML data in graphical form will display an error indicating where in the XML the error lies. Thus, the XML editor is a convenient way to check the validity of DataSet schemas you design.



Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net