标题 | 数据库生成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 } |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。