從SQL內讀數(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/output.xml";
SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=;database=db");
String strSql = "SELECT FirstName, LastName FROM employees";
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();
}
}
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請
點擊舉報。