[C#] C#从sql server读取数据到xml文件的代码片段 →→→→→进入此内容的聊天室

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

回复 "C#从sql server读取数据到xml文件的代码片段"

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

captcha