日期:2008-12-05  浏览次数:20929 次

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
%>