sql server 2000里面的表怎样导出为xml文件?
取出到dataset里头再存xml
http://dotnet.aspx.cc/ShowDetail.aspx?id=F3EB8683-DB3C-4460-ADB7-7C5C12348A11
利用OleDb对象,将数据库中全部表转换成XML文件
DataSet ds
ds 填充数据....
ds.WriteXml (MapPath("ss.xml"));
保存为xml 就好了...
xmlfromsqlsrv.aspx:
------------------------------------
<%@ Page Language="C#" Debug="true" Src="xmlfromsqlsrv.cs"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="HowTo.Samples.ADONET" %>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
StringWriter writer = new StringWriter();
Console.SetOut(writer);
xmlfromsqlsrv myxmlfromsqlsrv = new xmlfromsqlsrv();
myxmlfromsqlsrv.Run();
output.InnerHtml = writer.ToString();
}
</script>
<html>
<body style="background-color:f6e4c6">
<tr><td><h4><xmp id="output" runat="server"/></h4></td></tr>
</body>
</html>
xmlfromsqlsrv.aspx.cs:
--------------------------------------------------------------
namespace HowTo.Samples.ADONET
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
public class xmlfromsqlsrv
{
public static void Main()
{
xmlfromsqlsrv myxmlfromsqlsrv = new xmlfromsqlsrv();
myxmlfromsqlsrv.Run();
}
public void Run()
{
String sConnection = "server=(local)NetSDK;Trusted_Connection=yes;database=northwind";
SqlConnection mySqlConnection = new SqlConnection(sConnection);
SqlCommand mySqlCommand = new SqlCommand("select * from customers FOR XML AUTO, XMLDATA", mySqlConnection);
mySqlCommand.CommandTimeout = 15;
try
{
mySqlConnection.Open();
// Now create the DataSet and fill it with xml data.
DataSet myDataSet1 = new DataSet();
myDataSet1.ReadXml((XmlTextReader)mySqlCommand.ExecuteXmlReader(), XmlReadMode.Fragment);
// Modify to match the other dataset
myDataSet1.DataSetName = "NewDataSet";
// Get the same data through the provider.
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("select * from customers", sConnection);
DataSet myDataSet2 = new DataSet();
mySqlDataAdapter.Fill(myDataSet2);
// Write data to files: data1.xml and data2.xml for comparison.
myDataSet1.WriteXml("data1.xml");
myDataSet2.WriteXml("data2.xml");
Console.WriteLine ("已将数据写入到输出文件:data1.xml 和 data2.xml");
Console.WriteLine ();
Console.WriteLine ("********************data1.xml********************");
Console.WriteLine (myDataSet1.GetXml());
Console.WriteLine ();
Console.WriteLine ("********************data2.xml********************");
Console.WriteLine (myDataSet2.GetXml());
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
mySqlConnection.Close();
}
}
}
}