利用OleDb对象,将数据库中全部表转换成...【转】

2024-05-07 13:18

本文主要是介绍利用OleDb对象,将数据库中全部表转换成...【转】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!



ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />


ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 


C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

ASP.NET Dataset让你在页面中使用XML格式的文件提供了便利。如果您的数据全部都在一个数据库中,该如何进行转换呢?如果你的数据库与OleDb兼容的话,下面就看看如何把数据库中的所有表转换成XML文件。文件名字与数据库中的表的名字相同。本代码包含两个版本:C#版本和VB.NET版本。 

C#版本:

<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int I = 0; I < schemaTable.Rows.Count; I++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[I].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[I].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[I].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml'>" + schemaTable.Rows[I].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


VB.NET版本:

<%@ Page Language="VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub

Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub

</script>

<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" οnclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>


对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。 

<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />

这篇关于利用OleDb对象,将数据库中全部表转换成...【转】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/967462

相关文章

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

mysql数据库重置表主键id的实现

《mysql数据库重置表主键id的实现》在我们的开发过程中,难免在做测试的时候会生成一些杂乱无章的SQL主键数据,本文主要介绍了mysql数据库重置表主键id的实现,具有一定的参考价值,感兴趣的可以了... 目录关键语法演示案例在我们的开发过程中,难免在做测试的时候会生成一些杂乱无章的SQL主键数据,当我们

Spring Boot 整合 MyBatis 连接数据库及常见问题

《SpringBoot整合MyBatis连接数据库及常见问题》MyBatis是一个优秀的持久层框架,支持定制化SQL、存储过程以及高级映射,下面详细介绍如何在SpringBoot项目中整合My... 目录一、基本配置1. 添加依赖2. 配置数据库连接二、项目结构三、核心组件实现(示例)1. 实体类2. Ma

python dict转换成json格式的实现

《pythondict转换成json格式的实现》本文主要介绍了pythondict转换成json格式的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下... 一开始你变成字典格式data = [ { 'a' : 1, 'b' : 2, 'c编程' : 3,

查看Oracle数据库中UNDO表空间的使用情况(最新推荐)

《查看Oracle数据库中UNDO表空间的使用情况(最新推荐)》Oracle数据库中查看UNDO表空间使用情况的4种方法:DBA_TABLESPACES和DBA_DATA_FILES提供基本信息,V$... 目录1. 通过 DBjavascriptA_TABLESPACES 和 DBA_DATA_FILES

Java实现数据库图片上传与存储功能

《Java实现数据库图片上传与存储功能》在现代的Web开发中,上传图片并将其存储在数据库中是常见的需求之一,本文将介绍如何通过Java实现图片上传,存储到数据库的完整过程,希望对大家有所帮助... 目录1. 项目结构2. 数据库表设计3. 实现图片上传功能3.1 文件上传控制器3.2 图片上传服务4. 实现

C#原型模式之如何通过克隆对象来优化创建过程

《C#原型模式之如何通过克隆对象来优化创建过程》原型模式是一种创建型设计模式,通过克隆现有对象来创建新对象,避免重复的创建成本和复杂的初始化过程,它适用于对象创建过程复杂、需要大量相似对象或避免重复初... 目录什么是原型模式?原型模式的工作原理C#中如何实现原型模式?1. 定义原型接口2. 实现原型接口3

使用Dify访问mysql数据库详细代码示例

《使用Dify访问mysql数据库详细代码示例》:本文主要介绍使用Dify访问mysql数据库的相关资料,并详细讲解了如何在本地搭建数据库访问服务,使用ngrok暴露到公网,并创建知识库、数据库访... 1、在本地搭建数据库访问的服务,并使用ngrok暴露到公网。#sql_tools.pyfrom

Java实现数据库图片上传功能详解

《Java实现数据库图片上传功能详解》这篇文章主要为大家详细介绍了如何使用Java实现数据库图片上传功能,包含从数据库拿图片传递前端渲染,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、前言2、数据库搭建&nbsChina编程p; 3、后端实现将图片存储进数据库4、后端实现从数据库取出图片给前端5、前端拿到

IDEA连接达梦数据库的详细配置指南

《IDEA连接达梦数据库的详细配置指南》达梦数据库(DMDatabase)作为国产关系型数据库的代表,广泛应用于企业级系统开发,本文将详细介绍如何在IntelliJIDEA中配置并连接达梦数据库,助力... 目录准备工作1. 下载达梦JDBC驱动配置步骤1. 将驱动添加到IDEA2. 创建数据库连接连接参数