标题 | 数据库生成xml的两个方法 |
范文 | 第一个示例方法: 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 表, conn); 5 sqlcommandbuilder thisbulder = new sqlcommandbuilder(da); 6 dataset ds = new dataset(); 7 da.fill(ds); 8 ds.writexml(@c:\temp.xml); 第二个示例方法: 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.filestream 8 (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 } |
随便看 |
|
在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。