Updategram 是模板;因此,可以传递参数。 有关将参数传递给模板的详细信息,请参阅 Updategram 安全注意事项(SQLXML 4.0)。
Updategram 允许将 NULL 作为参数值传递。 若要传递 NULL 参数值,请指定 nullvalue 属性。 然后将分配给 nullvalue 特性的值作为参数值提供。 Updategram 会将此值视为 NULL。
注释
在 <sql:header> 和 <updg:header>中,应将指定 nullvalue 为未限定;而在中 <updg:sync>,将指定 nullvalue 为限定符(例如, updg:nullvalue)。
例子
若要使用以下示例创建工作示例,必须满足 运行 SQLXML 示例的要求中指定的要求。
在使用 updategram 示例之前,请注意以下事项:
- 这些示例使用默认映射(即,updategram 中未指定映射架构)。 有关使用映射架构的更新报的更多示例,请参阅在 Updategram 中指定带批注的映射架构(SQLXML 4.0)。
答: 将参数传递给 updategram
在此示例中,updategram 更改 HumanResources.Shift 表中员工的姓氏。 updategram 传递了两个参数:ShiftID,用于唯一标识 Shift 和 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
将上面的 updategram 复制到记事本,并将其另存为 UpdategramWithParameters.xml文件。
在“使用 ADO 执行 SQLXML 4.0 查询”中准备 SQLXML 4.0 测试脚本(Sqlxml4test.vbs),以便在以下行后面
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. 将 NULL 作为参数值传递给 updategram
在执行 updategram 时,会将“isull”值分配给要设置为 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
将上面的 updategram 复制到记事本,并将其另存为 UpdategramPassingNullvalues.xml文件。
在“使用 ADO 执行 SQLXML 4.0 查询”中准备 SQLXML 4.0 测试脚本(Sqlxml4test.vbs),以便在以下行后面
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)