Visual Studio 2005 Cookbook – Database, Writing In-Memory Data Tables to an XML File
Recipe 13.9. 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")
These statements generate the following XML content:
<?xml version="1.0" standalone="yes"?> <NewDataSet> <UnitedStates> <ShortName>WA</ShortName> <FullName>Washington</FullName> <Admission>1889-11-11T00:00:00-08:00</Admission> <Population>5894121</Population> </UnitedStates> <UnitedStates> <ShortName>MT</ShortName> <FullName>Montana</FullName> <Admission>1889-11-08T00:00:00-08:00</Admission> <Population>902195</Population> </UnitedStates> </NewDataSet>
You can also output the XML directly Read More >>
No comments yet.



