Writing Data as XML

As you learned yesterday, a DataSet can be serialized and deserialized to and from XML using the XmlSerializer class of the System.Xml.Serialization namespace. This process occurs when a DataSet is remoted across AppDomains or returned from an XML Web Service.

However, the DataSet also exposes the GetXml and WriteXml methods, which can be called directly to serialize the DataSet to XML. These methods function identically by writing out the contents of the DataSet using the Current row version that includes all modified and added rows and omits all deleted rows. For example, using the TitlesDs strongly typed DataSet defined in yesterday's lesson, the following code can be written to find a particular Sams title and lower its ...

Get Sams Teach Yourself ADO.NET in 21 Days 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.