The DataSet class can be used to read a relational database table and write this table to an XML file. This article shows you how you can write data from a database to an XML file using data set object.

You use WriteXml method to write a dataset data to an XML file.

In this sample example, first I create a dataset connection to the Northwind database. After that I create a data adapter object and selects all records of Customers table. After that I can fill method to fill a dataset from the data adapter.

Once a dataset if filled with records, I call WriteXml method to write data to an XML file "CustTableDt.xml" in C:\ dir.

C# Corner founder, 10-times Microsoft MVP, technical author, and software architect. Mahesh authored his first book, A Programmer’s Guide to ADO.NET in C# with APress at the age of 25. C# Corner is a memb... Read more