Visual Basic World

Just another Visual Basic weblog

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 >>

Advertisement

July 9, 2008 - Posted by | database, programing, vb.net | , , , , , , , , , ,

No comments yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.