Database Reference
In-Depth Information
You can import and export the structure of a data set as an XML schema using
System.Data.DataSet 's ReadXmlSchema and WriteXmlSchema methods.
You can read the data (and, optionally, the schema) of a data set from ReadXml()
and write it to an xml file with WriteXml(). This can be useful when exchanging
data with another application or making a local copy of a data set.
You can bind a data set to an XML document (an instance of
System.Xml.XmlDataDocument ). The data set and data document are synchronized,
so either ADO.NET or XML operations can be used to modify it.
Let's look at one of these in action: copying a data set to an XML file.
Note If you're unfamiliar with XML, don't worry. ADO.NET doesn't require any detailed knowledge of it. Of
course, the more you know, the better you can understand what's happening transparently.
Try It: Extracting a Data Set to an XML File
You can preserve the contents and schema of a data set in one XML file using the data set's WriteXml
method or in separate files using WriteXml() and WriteXmlSchema() . WriteXml() is overloaded, and in this
example we'll show a version that extracts both data and schema.
1. Select the DataSetandDataAdapter project, right-click, and choose Add
Windows Form. From the opened dialog, make sure the Windows form is
selected, and rename Form1.cs to WriteXML.cs . Click OK to add this form to the
DataSetandDataAdapter project.
2. Select the WriteXML form by clicking the form's title bar, and set the Size
property's Width to 289 and Height to 124.
3. Drag a Button control to the form, and position it toward the center of the
form. Select this Button control, navigate to the Properties window, and set the
following properties:
Set the Name property to btnXML.
For the Location property, set X to 74 and Y to 30.
For the Size property, set Width to 128 and Height to 23.
Set the Text property to Generate XML.
4. Now your WriteXML form in the Design view should look like Figure 15-15.
 
Search WWH ::




Custom Search