asp下将数据库中的信息存储至XML文件中
作者:
asp下将数据库中的信息存储至XML文件中
save.asp
<!-- #include file="adovbs.inc" -->
<%
' Constants file included above.
' 如果文件存在则删除
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath("db_xml.xml")) Then
objFSO.DeleteFile Server.MapPath("db_xml.xml")
End IF
Set objFSO = Nothing
'变量声明
Dim cnnXML ' ADO connection
Dim rstXML ' ADO recordset
'创建数据连接对象
Set cnnXML = Server.CreateObject("ADODB.Connection")
' 这是连接access数据库的例子:
'cnnXML.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
' & Server.MapPath("db_scratch.mdb") & ";"
' 下面以Sqlserver为例子讲解:
cnnXML.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
Set rstXML = Server.CreateObject("ADODB.Recordset")
Set rstXML = cnnXML.Execute("SELECT * FROM scratch ORDER BY id;")
Response.Write "<p>Saving data as XML...</p>" & vbCrLf
' 保存至xml格式.
rstXML.Save Server.MapPath("db_xml.xml"), adPersistXML
' 关闭对象、释放资源
rstXML.Close
Set rstXML = Nothing
cnnXML.Close
Set cnnXML = Nothing
Response.Write "<p>XML file written...</p>" & vbCrLf
Response.Write "<p>Click <a href=""db_xml.xml"">here</a> to view the file.</p>" & vbCrLf
%>
<!-- #include file="adovbs.inc" -->
<%
' Constants file included above.
' 如果文件存在则删除
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath("db_xml.xml")) Then
objFSO.DeleteFile Server.MapPath("db_xml.xml")
End IF
Set objFSO = Nothing
'变量声明
Dim cnnXML ' ADO connection
Dim rstXML ' ADO recordset
'创建数据连接对象
Set cnnXML = Server.CreateObject("ADODB.Connection")
' 这是连接access数据库的例子:
'cnnXML.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
' & Server.MapPath("db_scratch.mdb") & ";"
' 下面以Sqlserver为例子讲解:
cnnXML.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
Set rstXML = Server.CreateObject("ADODB.Recordset")
Set rstXML = cnnXML.Execute("SELECT * FROM scratch ORDER BY id;")
Response.Write "<p>Saving data as XML...</p>" & vbCrLf
' 保存至xml格式.
rstXML.Save Server.MapPath("db_xml.xml"), adPersistXML
' 关闭对象、释放资源
rstXML.Close
Set rstXML = Nothing
cnnXML.Close
Set cnnXML = Nothing
Response.Write "<p>XML file written...</p>" & vbCrLf
Response.Write "<p>Click <a href=""db_xml.xml"">here</a> to view the file.</p>" & vbCrLf
%>
您可能感兴趣的文章:
- asp access数据库并生成XML文件范例
- Javascript+XMLHttpRequest+asp.net无刷新读取数据库数据
- ASP XML操作类代码
- ASP读取XML实例 优酷专辑采集程序 雷锋版
- ASP XMLDom在服务器端操作XML文件的主要方法和实现
- Asp操作Xml的精炼类,含示例代码
- ASP.NET+XML打造网络硬盘原理分析
- asp xmlhttp下载一句话
- asp.net TreeView与XML三步生成列表树
- Asp 解析 XML并分页显示源码
- ASP.NET中XML转JSON的方法实例
- ASP.net处理XML数据实例浅析
- ASP.NET XmlDocument类详解
- asp.net中XML如何做增删改查操作
- asp控制xml数据库的经典代码