|
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Xml;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void xsp_ExportData()
{
SqlPipe pipe = SqlContext.Pipe;
using (SqlConnection con = new SqlConnection("context connection=true"))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM USERS", con))
{
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
XmlDocument document = new XmlDocument();
XmlDeclaration xmlDeclaration = document.CreateXmlDeclaration("1.0", "utf-8", null);
XmlElement rootNode = document.CreateElement("USERS");
document.AppendChild(rootNode);
while (reader.Read())
{
XmlElement parentNode = document.CreateElement("USER");
parentNode.SetAttribute("ID", reader["userid"].ToString());
parentNode.InnerText = reader["FNAME"].ToString();
rootNode.AppendChild(parentNode);
}
pipe.Send(document.InnerXml); // this will print the XML output
reader.Close();
pipe.ExecuteAndSend(cmd); // This will show the result
SqlDataRecord rec = new SqlDataRecord();
pipe.SendResultsStart(rec);
pipe.SendResultsRow(rec);
pipe.SendResultsStart(rec);
con.Close();
}
}
}
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Did you like his post?
Oh, lets go a bit further to know him better.
Visit his Website :
www.abhisheksur.com to know more about Abhishek.
Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.
http://bit.ly/EXPERTCookBook
Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.
Working as a VP product of
APPSeCONNECT, an integration platform of future, he does all sort of innovation around the product.
Have any problem? Write to him in his
Forum.
You can also mail him directly to
abhi2434@yahoo.com
Want a Coder like him for your project?
Drop him a mail to
contact@abhisheksur.com
Visit His Blog
Dotnet Tricks and Tips
Dont forget to vote or share your comments about his Writing