共用方式為


將參數傳遞至 Updategrams (SQLXML 4.0)

Updategrams 是範本,所以您可以將參數傳遞給它們。如需有關將參數傳遞給範本的詳細資訊,請參閱<Updategram 安全性考量 (SQLXML 4.0)>。

Updategrams 可讓您將 NULL 當做參數值來傳遞。若要傳遞 NULL 參數值,您會指定 nullvalue 屬性。然後會將指派給 nullvalue 屬性的值當做參數值來提供。Updategrams 將此值視為 NULL。

[!附註]

在 <sql:header> 和 <updg:header> 中,您應該將 nullvalue 指定為不合格;但是在 <updg:sync> 中,您應該將 nullvalue 指定為合格 (例如 updg:nullvalue)。

範例

若要使用下列範例建立工作範例,您必須符合<執行 SQLXML 範例的需求>中指定的需求。

使用 Updategram 範例之前,請注意下列事項:

A. 傳遞參數給 updategram

在此範例中,updategram 會變更 umanResources.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 查詢>。