Passing Parameters to Updategrams (SQLXML 4.0)
Updategrams are templates; therefore, you can pass them parameters.
Updategrams allow you to pass NULL as a parameter value. To pass the NULL parameter value, you specify the nullvalue attribute. The value that is assigned to the nullvalue attribute is then provided as the parameter value. Updategrams treat this value as NULL.
Note
In <sql:header> and <updg:header>, you should specify the nullvalue as unqualified; whereas, in <updg:sync>, you specify the nullvalue as qualified (for example, updg:nullvalue).
Examples
To create working samples using the following examples, you must meet the requirements specified in Requirements for Running SQLXML Examples.
Before using the updategram examples, note the following:
- The examples use default mapping (that is, no mapping schema is specified in the updategram). For more examples of updategrams that use mapping schemas, see Specifying an Annotated Mapping Schema in an Updategram (SQLXML 4.0).
- Updates are applied to the tables in the AdventureWorks database. You can restore the AdventureWorks database. For more information, see Reinstalling Sample Databases from Script.
A. Passing parameters to an updategram
In this example, the updategram changes the last name of an employee in the HumanResources.Shift table. The updategram is passed two parameters: ShiftID, which is used to uniquely identify a shift, and Name.
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:header>
<updg:param name="ShiftID"/>
<updg:param name="Name" />
</updg:header>
<updg:sync >
<updg:before>
<HumanResources.Shift ShiftID="$ShiftID" />
</updg:before>
<updg:after>
<HumanResources.Shift Name="$Name" />
</updg:after>
</updg:sync>
</ROOT>
To test the updategram
Copy the updategram above into Notepad and save it to file as UpdategramWithParameters.xml.
Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the updategram.
For more information, see Using ADO to Execute SQLXML 4.0 Queries.
B. Passing NULL as a parameter value to an updategram
In executing an updategram, the "isnull" value is assigned to the parameter that you want to set to NULL. Updategram converts the "isnulll" parameter value to NULL and processes it accordingly.
The following updategram sets an employee title to NULL:
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:header nullvalue="isnull" >
<updg:param name="EmployeeID"/>
<updg:param name="ManagerID" />
</updg:header>
<updg:sync >
<updg:before>
<HumanResources.Employee EmployeeID="$EmployeeID" />
</updg:before>
<updg:after>
<HumanResources.Employee ManagerID="$ManagerID" />
</updg:after>
</updg:sync>
</ROOT>
To test the updategram
Copy the updategram above into Notepad and save it to file as UpdategramPassingNullvalues.xml.
Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the updategram.
For more information, see Using ADO to Execute SQLXML 4.0 Queries.
See Also
Reference
Updategram Security Considerations (SQLXML 4.0)