Passing Parameters to Updategrams (SQLXML 4.0)

Applies to: SQL Server Azure SQL Database

Updategrams are templates; therefore, you can pass them parameters. For more information about passing parameters to templates, see Updategram Security Considerations (SQLXML 4.0).

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. Prepare the SQLXML 4.0 test script (Sqlxml4test.vbs) in Using ADO to Execute SQLXML 4.0 Queries to execute the updategram by adding the following lines after the cmd.Properties("Output Stream").Value = outStream:

    cmd.NamedParameters = True  
    ' CreateParameter arguments: Name, Type, Direction, Size, Value  
    cmd.Parameters.Append cmd.CreateParameter("@ShiftID",  2, 1,  0, 1)  
    cmd.Parameters.Append cmd.CreateParameter("@Name",   200, 1, 50, "New Name")  
    

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. Prepare the SQLXML 4.0 test script (Sqlxml4test.vbs) in Using ADO to Execute SQLXML 4.0 Queries to execute the updategram by adding the following lines after the cmd.Properties("Output Stream").Value = outStream:

    cmd.NamedParameters = True  
    ' CreateParameter arguments: Name, Type, Direction, Size, Value   
    cmd.Parameters.Append cmd.CreateParameter("@EmployeeID", 3, 1, 0, 1)  
    cmd.Parameters.Append cmd.CreateParameter("@ManagerID",  3, 1, 0, Null)  
    

See Also

Updategram Security Considerations (SQLXML 4.0)