Generate xml method based on database

Source: Internet
Author: User
Sqlconnection Conn =   New Sqlconnection ();
Conn. connectionstring =   " Server = 127.0.0.1; user id = sa; Password = fdahgdrethj31313210212121; database = northwind; persist Security info = true " ;
Conn. open ();
Sqldataadapter da =   New Sqldataadapter ( " Select * from table " , Conn );
Sqlcommandbuilder thisbulder =   New Sqlcommandbuilder (DA );
Dataset DS =   New Dataset ();
Da. Fill (DS );
DS. writexml ( @" C: \ Temp. xml " );
========================================================== ==============================================

Private   Void Writexmltofile (Dataset thisdataset) {
If (Thisdataset =   Null ) {Return;}
// Create a file name to write.
String Filename =   " Myxmldoc. xml " ;
// Create the filestream to write.
System. Io. filestream myfilestream =   New System. Io. filestream
(Filename, system. Io. filemode. Create );
// Create an xmltextwriter with the filestream.
System. xml. xmltextwriter myxmlwriter =  
New System. xml. xmltextwriter (myfilestream, system. Text. encoding. Unicode );
// Write to the file with the writexml method.
Thisdataset. writexml (myxmlwriter );
Myxmlwriter. Close ();
}

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.