Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Sunday, September 12, 2010

Database, Reading an XML File into In-Memory Data Tables

Problem

You previously exported a DataSet to an XML file, and now you need to get it back.

Solution

Use the DataSet object's ReadXML() method to restore data from a previously generated XML export.

Discussion

Recipe 13.9 exports some XML and a related schema for a table with state-specific information. To read it back into a DataSet object, use the following code:
Dim stateSet As New Data.DataSet
 stateSet.ReadXmlSchema("c:\StateSchema.xml")
 stateSet.ReadXml("c:\StateInfo.xml")

Database, Writing In-Memory Data Tables to an XML File

Problem

You have some data in a DataSet object, and you would like to export it to an XML file for later reimportation.

Solution

Use the DataSet's WriteXML() method to send the DataSet content to the file in a common XML format.

Discussion

Recipe 13.8 builds a DataTable object with two state-specific records. The following code adds that table to a DataSet object and writes its records to an XML file:
Dim fullDataSet As New Data.DataSet
 fullDataSet.Tables.Add(stateTable)
 fullDataSet.WriteXml("C:\StateInfo.xml")