Hi friends i have seen many sites where i can find how to convert the sql stored data to an xml file but to my surprise i haven't got my solution and finally after many trials i got a good solution which is working 100% and with this u can just convert all u'r sql data to a xml format. Here is the code If it helped don't forget to give a comment and vist here for all u r solutions.
Procedure:
1.Create a aspx page and a xml file with name getdata. Then write the fallowing code in .cs file and bingo that's it.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MANISINPC-003;Initial Catalog=LinkDirectoryDB;Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("select * from SubCategoryDetails", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "SubCategoryDetails");
StreamWriter xmldoc = new StreamWriter(Server.MapPath("~/getxml.xml"), false);
ds.WriteXml(xmldoc);
xmldoc.Close();
Response.Redirect("getxml.xml");
}
}
Have fun dude
Thursday, September 24, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment