Jaa


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:

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

  1. Copy the updategram above into Notepad and save it to file as UpdategramWithParameters.xml.

  2. 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

  1. Copy the updategram above into Notepad and save it to file as UpdategramPassingNullvalues.xml.

  2. 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)

Help and Information

Getting SQL Server 2005 Assistance