欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#從數(shù)據(jù)庫讀取數(shù)據(jù)到DataSet并保存到xml文件的方法

 更新時間:2015年04月03日 09:42:49   作者:令狐不聰  
這篇文章主要介紹了C#從數(shù)據(jù)庫讀取數(shù)據(jù)到DataSet并保存到xml文件的方法,涉及C#操作DataSet保存到XML文件的技巧,需要的朋友可以參考下

本文實例講述了C#從數(shù)據(jù)庫讀取數(shù)據(jù)到DataSet并保存到xml文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

DataSet有一個WriteXml方法可以直接將數(shù)據(jù)保存到xml文件

using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.IO;
public class TestWriteXML
{
  public static void Main()
  {
    String strFileName = c:/temp/out.xml;
    SqlConnection conn = new SqlConnection(server=localhost;uid=sa;pwd=;database=db);
    String strSql = SELECT name,age FROM people;
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(strSql, conn);
    // Build the DataSet
    DataSet ds = new DataSet();
    adapter.Fill(ds, employees);
    // Get a FileStream object
    FileStream fs = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Write);
    // Apply the WriteXml method to write an XML document
    ds.WriteXml(fs);
    fs.Close();
  }
}

希望本文所述對大家的C#程序設(shè)計有所幫助。

相關(guān)文章

最新評論