Solved

return SqlReader results as XML

Posted on 2013-11-20
2
292 Views
Last Modified: 2013-11-20
Hi,

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);
            writer.WriteStartDocument();
            writer.WriteStartElement("LogSet");

            while (sqlRdr.Read())
            {
                writer.WriteStartElement("Log");

                writer.WriteStartElement("EntryID");
                writer.WriteValue(sqlRdr["EntryID"].ToString());
                writer.WriteEndElement();

               //and so on

Open in new window


Is there an easier, elegant way  to do this?

thanks!
0
Comment
Question by:olmuser
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39662382
A similar question was asked on StackOverflow: (stackoverflow.com/questions/16768263/generate-xml-using-c-sharp-from-sql-server-data).

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

Author Closing Comment

by:olmuser
ID: 39662660
yeah I posted that question too :-)
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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