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

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.