JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Writing Datasets to XML and Reading Datasets from XML

As you know, the data in datasets is transported using XML. In this topic, I'll take a closer look at that XML, using the DataSetXML example on the CD-ROM. This example writes the authors table of the pubs database to an XML file, dataset.xml, using the WriteXml method, and then reads that file back into a second dataset using the ReadXml method, as you see in Figure 22.4.

Figure 22.4: Writing a dataset's XML and reading that XML back in.

Here's the code—when the user clicks the "Write existing dataset to XML file" button, the authors table in the DataSet11 dataset is written to dataset.xml, and when the user clicks the "Create new dataset from XML file" button, a new dataset is created and reads its data in from dataset.xml:

Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
    Dim ds As New DataSet()
    DataGrid1.SetDataBinding(ds, "authors")
End Sub

You can see the dataset's data in the dataset.xml file (another file, DataSet1.xsd, will hold the XML schema, because this is a typed dataset):

<?xml version="1.0" standalone="yes"?>
<DataSet1 xmlns="">
    <phone>408 496-7223</phone>
    <address>10932 Bigge Rd.</address>
    <city>Menlo Park</city>
    <phone>415 986-7020</phone>
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor