[C#] 从SQL内读数据到XML →→→→→进入此内容的聊天室

来自 , 2020-10-19, 写在 C#, 查看 215 次.
URL http://www.code666.cn/view/cabad3b9
  1. using System;
  2. using System.Data;
  3. using System.Xml;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6.  
  7. public class TestWriteXML
  8. {
  9. public static void Main()
  10. {
  11.  
  12. String strFileName=c:/temp/output.xml;
  13.  
  14. SqlConnection conn = new SqlConnection(server=localhost;uid=sa;pwd=;database=db);
  15.  
  16. String strSql = SELECT FirstName, LastName FROM employees;
  17.  
  18. SqlDataAdapter adapter = new SqlDataAdapter();
  19.  
  20. adapter.SelectCommand = new SqlCommand(strSql,conn);
  21.  
  22. // Build the DataSet
  23. DataSet ds = new DataSet();
  24.  
  25. adapter.Fill(ds, employees);
  26.  
  27. // Get a FileStream object
  28. FileStream fs = new FileStream(strFileName,FileMode.OpenOrCreate,FileAccess.Write);
  29.  
  30. // Apply the WriteXml method to write an XML document
  31. ds.WriteXml(fs);
  32.  
  33. fs.Close();
  34.  
  35. }
  36. }
  37.  
  38. //csharp/1136

回复 "从SQL内读数据到XML"

这儿你可以回复上面这条便签

captcha