将参数传递给 Updategram (SQLXML 4.0)

Updategram 为模板,因此您可以向其传递参数。有关将参数传递给模板的详细信息,请参阅 updategram 的安全注意事项 (SQLXML 4.0)

Updategram 允许您将 NULL 作为参数值传递。若要传递 NULL 参数值,应指定 nullvalue 属性。然后,赋给 nullvalue 属性的值将作为参数值提供。Updategram 将该值视为 NULL。

注意注意

在 <sql:header> 和 <updg:header> 中,应将 nullvalue 指定为非限定的;而在 <updg:sync> 中,应将 nullvalue 指定为限定的(例如 updg:nullvalue)。

示例

若要创建使用以下示例的工作示例,则必须满足运行 SQLXML 示例的要求 中指定的要求。

在使用 updategram 示例前,请注意以下事项:

A. 将参数传递给 updategram

在本示例中,updategram 更改了 HumanResources.Shift 表中一位雇员的姓氏。向 updategram 传递了两个参数:ShiftID(用于唯一标识轮班)和 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>

测试 updategram

  1. 将上面的 updategram 复制到记事本中并将其另存为 UpdategramWithParameters.xml 文件。

  2. 创建并使用 SQLXML 4.0 测试脚本 (Sqlxml4test.vbs) 以执行 updategram。

    有关详细信息,请参阅使用 ADO 执行 SQLXML 4.0 查询

B. 将 NULL 作为参数值传递给 updategram

在执行 updategram 的过程中,会将“isnull”值赋给要设置为 NULL 的参数。Updategram 将“isnulll”参数值转换为 NULL 并对其进行相应处理。

下面的 updategram 将一位雇员的职务设置为 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>

测试 updategram

  1. 将上面的 updategram 复制到记事本中并将其另存为 UpdategramPassingNullvalues.xml 文件。

  2. 创建并使用 SQLXML 4.0 测试脚本 (Sqlxml4test.vbs) 以执行 updategram。

    有关详细信息,请参阅使用 ADO 执行 SQLXML 4.0 查询