将ADO方便的转化为XML文件
类别: ASP教程
<!-- #include file="adovbs.inc" -->
<%
\' 删除已经存在的文件
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 连接
Dim rstXML \' ADO 记录集
Set cnnXML = Server.CreateObject("ADODB.Connection")
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
%>
<%
\' 删除已经存在的文件
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 连接
Dim rstXML \' ADO 记录集
Set cnnXML = Server.CreateObject("ADODB.Connection")
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应用程序
- 下一篇: ASP中巧用SPLIT()函数生成SQL查询语句
-= 资 源 教 程 =-
文 章 搜 索