This section describes two simple sample codes for generating xml from a database.

Source: Internet
Author: User
Method 1: SqlConnectionconnnewSqlConnection (); 2conn. connectionString & quot; Server127.0.0.1; UserIDsa; Passwordfdahgdrethj31313210212121; Databasenorthwind; PersistSecurityInfoTrue & quot; 3conn. open (); 4 SqlData first example method:

1 SqlConnection conn = new SqlConnection (); 2 conn. connectionString = "Server = 127.0.0.1; User ID = sa; Password = fdahgdrethj31313210212121; Database = northwind; Persist Security Info = True"; 3 conn. open (); 4 SqlDataAdapter da = new SqlDataAdapter ("select * from table", conn); 5 SqlCommandBuilder thisBulder = new SqlCommandBuilder (da); 6 DataSet ds = new DataSet (); 7 da. fill (ds); 8 ds. writeXml (@ "C: \ temp. xml ");

Method 2:

1 private void WriteXmlToFile(DataSet thisDataSet)2 {3 if (thisDataSet == null) { return; }4 // Create a file name to write to.5 string filename = "myXmlDoc.xml";6 // Create the FileStream to write with.7 System.IO.FileStream myFileStream = new System.IO.FileStream8 (filename, System.IO.FileMode.Create);9 // Create an XmlTextWriter with the fileStream.10 System.Xml.XmlTextWriter myXmlWriter =11 new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);12 // Write to the file with the WriteXml method.13 thisDataSet.WriteXml(myXmlWriter);14 myXmlWriter.Close();15 }

The above is the details of the two simple sample code for generating xml in the database. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.