Solved

return SqlReader results as XML

Posted on 2013-11-20
2
287 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

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 titlecase+vb.net 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