asp下将数据库中的信息存储至XML文件中

2018-09-06 10:57

阅读:468

  save.asp
<%
Constantsfileincludedabove.
如果文件存在则删除
DimobjFSO
SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
IfobjFSO.FileExists(Server.MapPath(db_xml.xml))Then
objFSO.DeleteFileServer.MapPath(db_xml.xml)
EndIF
SetobjFSO=Nothing
变量声明
DimcnnXMLADOconnection
DimrstXMLADOrecordset
创建数据连接对象
这是连接access数据库的例子:
cnnXML.OpenProvider=Microsoft.Jet.OLEDB.4.0;DataSource=_
&Server.MapPath(db_scratch.mdb)&;
下面以Sqlserver为例子讲解:
cnnXML.OpenProvider=SQLOLEDB;DataSource=10.2.1.214;_
&InitialCatalog=samples;UserId=samples;Password=password;_
&ConnectTimeout=15;NetworkLibrary=dbmssocn;
SetrstXML=Server.CreateObject(ADODB.Recordset)
SetrstXML=cnnXML.Execute(SELECT*FROMscratchORDERBYid;)
Response.Write<p>SavingdataasXML...</p>&vbCrLf
保存至xml格式.
rstXML.SaveServer.MapPath(db_xml.xml),adPersistXML
关闭对象、释放资源
rstXML.Close
SetrstXML=Nothing
cnnXML.Close
SetcnnXML=Nothing
Response.Write<p>XMLfilewritten...</p>&vbCrLf
Response.Write<p>Click<ahref=db_xml.xml>here</a>toviewthefile.</p>&vbCrLf
%>


评论


亲,登录后才可以留言!