Click here to Skip to main content
15,886,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am implementing a service that get a sql "Select command"query and transform it to xml file with respect to the selected query.
any code or example please?
Posted
Comments
Tomas Takac 10-Nov-14 3:03am    
any code or example of your work please?

Why using C#? SQL server can provide you with a XML version of the query - http://msdn.microsoft.com/en-us/library/ms178107.aspx[^]
 
Share this answer
 
Comments
Maciej Los 10-Nov-14 3:54am    
+5
Kornfeld Eliyahu Peter 10-Nov-14 4:06am    
Thank you...
What you need an output of an sql query to xml.if so you can use the below code.


C#
using (System.Data.SqlClient.SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstringname"].ConnectionString))
    using (System.Data.SqlClient.SqlCommand cmd = c.CreateCommand())
    {
        cmd.CommandText = "yourstoredprocedure";
        cmd.CommandType = CommandType.StoredProcedure;

        c.Open();

        System.Xml.XmlReader r = cmd.ExecuteXmlReader();
        XmlDocument document = new XmlDocument();
        document.Load(r);

        Response.ContentType = "text/xml";
        document.Save(Response.Output);

        c.Close();
    }

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900