return SqlReader results as XML

Posted on 2013-11-20
Last Modified: 2013-11-20

I have an interface in a Web service that returns XML output. The output is queried from a MS SQL database by caling stored procedure. While the stored proc itself is not returning XML, and I don't have any control over it, I need to return the result set as XML.

Right now, I'm using  XmlWriter.

            StringBuilder sbLog = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sbLog);

            while (sqlRdr.Read())


               //and so on

Open in new window

Is there an easier, elegant way  to do this?

Question by:olmuser
LVL 26

Accepted Solution

Shaun Kline earned 500 total points
ID: 39662382
A similar question was asked on StackOverflow: (

In this example, the data was returned into a DataTable using a SQLDataAdapter. From there, the methods WriteXml and WriteXmlSchema were used.

Author Closing Comment

ID: 39662660
yeah I posted that question too :-)

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DataGridView 2 29
Problem to ToolkitScriptManager 2 30
crm development 2 37
Make all values in arrayist to 22 0
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now