O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving a DataSet as XML

A DataSet can be written as XML to variety of outputs, such as files or streams. Saving a DataSet as XML data to different output types often means using different method overloads in the DataSet. The specifics of saving a DataSet as XML data to various outputs are described in the following subsections.

Saving to a File

To save a DataSet in XML format to a file, call the DataSet.WriteXml() method, for example, like so:

C#
l_DataSet.WriteXml("\\MyDS.xml");

VB
l_DataSet.WriteXDml("\MyDS.xml")

WriteXml() throws an exception if there is a problem writing to the file. This is most typically caused by a sharing violation.

Saving Data to a Stream

You can save XML data to a stream by calling the DataSet.WriteXml(XmlWriter, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required