blogspot visit counter

Sunday, 6 October 2013

Generating Xml file From Mysql database

Generating XML FILE From MySQL database
Introduction :- In this article i have explain how to  generate  XML  File   from mysql database in asp.net .

Description :- In my previous article i have explain Crete and read XML file in asp.net   and  read data from XML file in asp.net . Now i am explain how to generate  XML file in  asp.net.



Step 1 :- Create table  for generate xml file using mysql database. Table structure as show below


CREATE TABLE `user_tab` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `User_Name` varchar(50) DEFAULT NULL,
  `Contact_No` varchar(50) DEFAULT NULL,
  `Donet_Values` float DEFAULT NULL,
  `Donate_Date` datetime DEFAULT NULL,
  `User_Email` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
)

GUI table structure as show below


Step 2:- create a new asp.net web  application and add  new page and write this code on web page as show below


//generat xml file and save in folder
    protected void Button1_Click(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=database Name;password=Your Password;Pooling=false;");
        con.Open();
        string str = "select * from slider_tab1 ";
        MySqlDataAdapter da = new MySqlDataAdapter(str,con);
        DataSet ds = new DataSet();
        da.Fill(ds,"Userinfo");
        ds.WriteXml(Server.MapPath("~/xmlfile/xml_file.xml"));
        lblmsg.Text = "XML File Created Successfully";
      
    }

Explanation -: Here i take a new asp.net web page and drag and drop  a asp.net button and one label for show the message file is created and write this code on asp.net button click event.

In this code i  have selected  all the data from mysql  database and create a object of mysql DataAdapter and create DaSet and fill all the DataAdapter values in Dataset and save the file in xml format in  xmlfile folder

Note- If you use mysql database then use the mysql to asp.net connector for connect the MySQL database to asp.net

1 comment:

Related Posts Plugin for WordPress, Blogger...