程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 在SQL2000查詢中使用XDR的例子

在SQL2000查詢中使用XDR的例子

編輯:關於SqlServer


XDR不會不知道吧?就是簡化的XML-Data啦。現在示范一個如何實現這樣的查詢

SELECT o.OrderID, o.OrderDate from Orders o, Customers c,

WHERE o.CustomerID = c.CustomerID and c.CompanyName = ?

Code:

<%@ Language=VBScript %>

<%

    Dim sConn

    sConn = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=Northwind; User ID=SA;PassWord=;" 

    Dim adoConn

    Set adoConn = Server.CreateObject("ADODB.Connection")

    adoConn.ConnectionString = sConn

    adoConn.CursorLocation = 3 ''adUseClIEnt

    adoConn.Open  

    Dim adoCmd

    Set adoCmd = CreateObject("ADODB.Command")

    Set adoCmd.ActiveConnection = adoConn

    adoCmd.CommandText = "Customer[@CompanyName=""Tortuga Restaurante""]"

    adoCmd.Dialect = "{ec2a4293-e898-11d2-b1b7-00c04f680c56}"  

    adoCmd.PropertIEs("Mapping Schema") = "Orders.XML"

    adoCmd.PropertIEs("Base Path") = "C:INETPUBWWWROOTPBA"

    adoCmd.PropertIEs("Output Stream") = Response 

    Response.write "<XML ID=''MyDataIsle''>"

    adoCmd.Execute , , 1024 ''adExecuteStream

    Response.write "</XML>"

%>


Result:

<XML ID="MyDataIsle">

<Customer CustomerID="TORTU" CompanyName="Tortuga Restaurante">

  <Order CustomerID="TORTU" OrderID="10276" OrderDate="1996-08-08T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10293" OrderDate="1996-08-29T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10304" OrderDate="1996-09-12T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10319" OrderDate="1996-10-02T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10518" OrderDate="1997-04-25T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10576" OrderDate="1997-06-23T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10676" OrderDate="1997-09-22T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10842" OrderDate="1998-01-20T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10915" OrderDate="1998-02-27T00:00:00" />

  <Order CustomerID="TORTU" OrderID="11069" OrderDate="1998-05-04T00:00:00" />

</Customer>

</XML> 

Orders.XML

<?XML version="1.0" ?>

<Schema xmlns="urn:schemas-microsoft-com:xml-data" XMLns:dt="urn:schemas-microsoft-com:datatypes"

xmlns:sql="urn:schemas-microsoft-com:XML-sql">

  <ElementType name="Order" sql:relation="Orders">

    <AttributeType name="CustomerID" />

    <AttributeType name="OrderID" />

    <AttributeType name="OrderDate" />

    <attribute type="CustomerID" sql:fIEld="CustomerID" />

    <attribute type="OrderID" sql:fIEld="OrderID" />

    <attribute type="OrderDate" sql:fIEld="OrderDate" />

  </ElementType>

  <ElementType name="Customer" sql:relation="Customers">

    <AttributeType name="CustomerID" />

    <AttributeType name="CompanyName" />

    <attribute type="CustomerID" sql:fIEld="CustomerID" />

    <attribute type="CompanyName" sql:fIEld="CompanyName" />

    <element type="Order">

      <sql:relationship key-relation="Customers" key="CustomerID" foreign-key="CustomerID" foreign-

relation="Orders" />

    </element>

  </ElementType>

</Schema>  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved