2000中生成的小技巧

来源:互联网 发布:幼儿园手指数算法视频 编辑:程序博客网 时间:2024/04/29 00:11
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  以前在介绍SQL2k的时候已经提到了SQL2k对XML的支持,使用forXML语句就可以很容易的把执行的结果转化为一个XML,这样可以在很大程度上提高系统运行效率和开发速度,详细的内容请参见BooksOnline。

  但是在使用ADO(RequiredADO2.6)访问返回的XML的方式和原来的Recordset是有所不同的。如果你还是使用Recordset访问的话,只能得到一个Unicode格式的XMLSchema,而无法得到XML的内容。

  其实这个问题也是很容易就能解决的,只是我自以为很熟悉ADO,没有仔细看Help,所以没有发现ADO是采用Stream的方式来得到和返回XML的。

  Command对象有两个属性,叫InputStream和OutputStream,属性的值是一个IUnknown接口。可以把一个XMLParser的接口赋给它,或者是直接用Request、Response等。这样的好处是不需要再去生成一个Recordset,不需要去保存这些数据,从而节省了系统开销。

  下面给大家一个简单的把XML用Response返回的Example:

<%@Language=VBScript%>
<!--#includefile="ADOVBS.inc"-->
<%
 DimobjConn,objCmd,i
 SetobjConn=Server.createobject("ADODB.CONNECTION")
 objConn.Open"Provider=SQLOLEDB.1;Password=;PersistSecurityInfo=True;UserID=sa;InitialCatalog=PBA;DataSource=(local)"
 SetobjCmd=Server.CreateObject("ADODB.Command")
 objCmd.ActiveConnection=objConn
 objCmd.Properties("OutputStream")=Response
 objCmd.Properties("XMLRoot")="root"
 objCmd.CommandText="Select*fromUserStatusforXMLAuto"
 Response.ContentType="text/xml"
 objCmd.Executei,,adExecuteStream
 SetobjCmd=Nothing
 objConn.Close
 SetobjConn=Nothing
%>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击