資源簡介
實現(xiàn)將數(shù)據(jù)庫的數(shù)據(jù)轉(zhuǎn)化為XML文件輸出
在VS2005+SQLSERVER2008測試通過。
代碼片段和文件信息
using?System;
using?System.Collections;
using?System.Configuration;
using?System.Data;
using?System.Linq;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.HtmlControls;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.xml.Linq;
using?System.xml;
using?System.Data.SqlClient;
public?partial?class?Wms_xml_sql_xml?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????string?ls_xmlname;
????????string?strSql?=?“select?mycolumn1mycolumn2.....?from?mytable“;
????????SqlConnection?conn?=?new?SqlConnection(“server=myserver;database=mydb;uid=**;pwd=**“);
????????SqlDataAdapter?da?=?new?SqlDataAdapter(strSql?conn);
????????SqlCommandBuilder?sb?=?new?SqlCommandBuilder(da);
????????DataSet?ds?=?new?DataSet();
????????da.Fill(ds?“message“);
????????//???創(chuàng)建xmltextwriter???
????????ls_xmlname?=?ds.Tables[0].Rows[0][“mycolumn1“].ToString();
????????xmlTextWriter?writer?=?new?xmlTextWriter(“C:\\xml\\“?+?ls_xmlname?+?“.xml“?System.Text.Encoding.UTF8);
????????//開始寫???
??????
評論
共有 條評論