Convert a .NET DataReader (Any Type) to XML

Category:
C#, VB.NET, ASP.NET
Type:
Snippets
Difficulty:
Intermediate

Author: sanjit tamhane

Version Compatibility: Visual Basic.NET

More information:
This is an extension to the code at http://www.freevbcode.com/ShowCode.asp?ID=5232, which converts a .NET SQLDataReader to XML. The enhancements are:
  1. Output XML data can be bind to DataGrid via Dataset in UI Layer
  2. Using IDataReader rather than SqlReader so can be used against any Data Provider.
  3. CreateCommand can be used against any data provider without parameters
User the CreateDataReader function below to obtain an IDataReader object to pass to the ReaderToXML function.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: