Использование диаграммы обновления в образце приложения ASP (SQLXML 4.0)
Приложение Active Server Pages (ASP) позволяет обновлять сведения о заказчике, содержащиеся в таблице Person.Person образца базы данных AdventureWorks2008R2 Microsoft SQL Server. Приложение выполняет следующие действия.
Запрашивает у пользователя идентификатор бизнес-сущности.
Использует это значение идентификатора для выполнения шаблона и получения контактной информации из таблицы Person.Person.
Отображает эти сведения с помощью формы HTML.
Затем пользователь может обновить контактную информацию, но не идентификатор бизнес-сущности (так как BusinessEntityID является первичным ключом). После того как пользователь вводит данные, выполняется диаграмма обновления, которой передаются все параметры из формы.
Следующий шаблон является первым шаблоном (GetPerson.xml). Сохраните этот шаблон в каталоге, который связан с виртуальным именем типа template.
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:header>
<sql:param name="bid"></sql:param>
</sql:header>
<sql:query>
SELECT *
FROM Person.Person
WHERE BusinessEntityID=@bid
FOR XML AUTO
</sql:query>
</root>
Следующий шаблон является вторым шаблоном (UpdatePerson.xml). Сохраните этот шаблон в каталоге, который связан с виртуальным именем типа template.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:header>
<updg:param name="bid"/>
<updg:param name="jobtitle" />
<updg:param name="firstname" />
<updg:param name="lastname" />
</updg:header>
<updg:sync >
<updg:before>
<Person.Person BusinessEntityID="$bid" />
</updg:before>
<updg:after>
<Person.Person BusinessEntityID="$bid"
JobTitle="$jobtitle"
FirstName="$firstname"
LastName="$lastname"/>
</updg:after>
</updg:sync>
</ROOT>
Следующий код является приложением ASP (SampleASP.asp). Сохраните его в каталоге, связанном с виртуальным корневым каталогом, созданным с помощью программы диспетчера служб Интернета. (Виртуальный корневой каталог не создается с помощью программы управления виртуальными каталогами служб IIS для SQL Server, так как управление виртуальными каталогами служб IIS для SQL Server не может обращаться к приложениям ASP или идентифицировать их.)
![]() |
---|
В коде необходимо заменить «ServerName» на имя сервера, на котором выполняются службы IIS. |
<% LANGUAGE=VBSCRIPT %>
<%
Dim BusinessEntityID
BusinessEntityID=Request.Form("bid")
%>
<html>
<body>
<%
'If a BusinessEntityID value is not yet provided, display this form.
if BusinessEntityID="" then
%>
<!-- If the BusinessEntityID has not been specified, display the form that allows users to enter an ID. -->
<form action="AdventureWorksPeople.asp" method="POST">
<br>
Enter BusinessEntityID: <input type=text name="bid"><br>
<input type=submit value="Submit this ID" ><br><br>
<-- Otherwise, if a BusinessEntityID is entered, display the second part of the form where the user can change customer information. -->
<%
else
%>
<form name="People" action="https://localhost/AdventureWorks2008R2/Template/UpdatePerson.xml" method="POST">
You may update customer information below.<br><br>
<!-- A comment goes here to separate the parts of the application or page. -->
<br>
<%
' Load the document in the parser and extract the values to populate the form.
Set objXML=Server.CreateObject("MSXML2.DomDocument")
ObjXML.setProperty "ServerHTTPRequest", TRUE
objXML.async=False
objXML.Load("https://localhost/AdventureWorks2008R2/Template/GetPerson.xml?bid=" & BusinessEntityID)
set objCustomer=objXML.documentElement.childNodes.Item(0)
' In retrieving data from the database, if a value in the column is NULL there
' is no attribute for the corresponding element. In this case,
' skip the error generation and go to the next attribute.
On Error Resume Next
Response.Write "Business Entity ID: <input type=text readonly=true style='background-color:silver' name=bid value="""
Response.Write objCustomer.attributes(0).value
Response.Write """><br><br>"
Response.Write "Job Title: <input type=text name=jobtitle value="""
Response.Write objCustomer.attributes(1).value
Response.Write """><br><br>"
Response.Write "First Name: <input type=text name=firstname value="""
Response.Write objCustomer.attributes(2).value
Response.Write """><br>"
Response.Write "Last Name: <input type=text name=lastname value="""
Response.Write objCustomer.attributes(3).value
Response.Write """><br><br>"
set objCustomer=Nothing
Set objXML=Nothing
%>
<input type="submit" value="Submit this change" ><br><br>
<input type=hidden name="contenttype" value="text/xml">
<input type=hidden name="eeid" value="<%=BusinessEntityID%>"><br><br>
<% end if %>
</form>
</body>
</html>