Categories: ADO.NET, DataSet, DataTable
Extension Method Example...
C# 3.0 added a cool feature to the toolkit called Extension Methods. Extension Methods are an extremely simple yet very powerful feature that allows you to bolt on additional method to existing objects without directly modifying those objects.
Convert DataTable to XML
The ADO.NET DataSet object has a method for retrieving the XML representation of the data in string format called "GetXml()".
A DataTable object however, does not. Here is a small function to quickly convert the DataTable contents to an XML string.

This function uses the DataTable's WriteXml function to write its contents into the StringWriter where the ToString() method gives us the XML string representation.
The result string will look like this.

It is relatively trivial then to load the string into and XmlDocument or XPathNavigator object.