利用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

相关文章

IDEA如何切换数据库版本mysql5或mysql8

《IDEA如何切换数据库版本mysql5或mysql8》本文介绍了如何将IntelliJIDEA从MySQL5切换到MySQL8的详细步骤,包括下载MySQL8、安装、配置、停止旧服务、启动新服务以及... 目录问题描述解决方案第一步第二步第三步第四步第五步总结问题描述最近想开发一个新应用,想使用mysq

Spring常见错误之Web嵌套对象校验失效解决办法

《Spring常见错误之Web嵌套对象校验失效解决办法》:本文主要介绍Spring常见错误之Web嵌套对象校验失效解决的相关资料,通过在Phone对象上添加@Valid注解,问题得以解决,需要的朋... 目录问题复现案例解析问题修正总结  问题复现当开发一个学籍管理系统时,我们会提供了一个 API 接口去

Oracle数据库使用 listagg去重删除重复数据的方法汇总

《Oracle数据库使用listagg去重删除重复数据的方法汇总》文章介绍了在Oracle数据库中使用LISTAGG和XMLAGG函数进行字符串聚合并去重的方法,包括去重聚合、使用XML解析和CLO... 目录案例表第一种:使用wm_concat() + distinct去重聚合第二种:使用listagg,

Java如何通过反射机制获取数据类对象的属性及方法

《Java如何通过反射机制获取数据类对象的属性及方法》文章介绍了如何使用Java反射机制获取类对象的所有属性及其对应的get、set方法,以及如何通过反射机制实现类对象的实例化,感兴趣的朋友跟随小编一... 目录一、通过反射机制获取类对象的所有属性以及相应的get、set方法1.遍历类对象的所有属性2.获取

Java读取InfluxDB数据库的方法详解

《Java读取InfluxDB数据库的方法详解》本文介绍基于Java语言,读取InfluxDB数据库的方法,包括读取InfluxDB的所有数据库,以及指定数据库中的measurement、field、... 首先,创建一个Java项目,用于撰写代码。接下来,配置所需要的依赖;这里我们就选择可用于与Infl

详谈redis跟数据库的数据同步问题

《详谈redis跟数据库的数据同步问题》文章讨论了在Redis和数据库数据一致性问题上的解决方案,主要比较了先更新Redis缓存再更新数据库和先更新数据库再更新Redis缓存两种方案,文章指出,删除R... 目录一、Redis 数据库数据一致性的解决方案1.1、更新Redis缓存、删除Redis缓存的区别二

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora

C#实现文件读写到SQLite数据库

《C#实现文件读写到SQLite数据库》这篇文章主要为大家详细介绍了使用C#将文件读写到SQLite数据库的几种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录1. 使用 BLOB 存储文件2. 存储文件路径3. 分块存储文件《文件读写到SQLite数据库China编程的方法》博客中,介绍了文

Android数据库Room的实际使用过程总结

《Android数据库Room的实际使用过程总结》这篇文章主要给大家介绍了关于Android数据库Room的实际使用过程,详细介绍了如何创建实体类、数据访问对象(DAO)和数据库抽象类,需要的朋友可以... 目录前言一、Room的基本使用1.项目配置2.创建实体类(Entity)3.创建数据访问对象(DAO

SQL Server数据库磁盘满了的解决办法

《SQLServer数据库磁盘满了的解决办法》系统再正常运行,我还在操作中,突然发现接口报错,后续所有接口都报错了,一查日志发现说是数据库磁盘满了,所以本文记录了SQLServer数据库磁盘满了的解... 目录问题解决方法删除数据库日志设置数据库日志大小问题今http://www.chinasem.cn天发