DOWNLOAD THE CODE:
Download the Code 23033.zip

To run Listing 3's updategram, save it to a file called updategram.xml in the directory you created for the virtual root in the previous example. Also, save the mapping schema in Listing 4 to a file called albumschema.xml in the same directory. Using Query Analyzer, run the SQL script that Listing 5 shows to create the Album table in the database you chose for the previous example. Finally, type the URL http://localhost/December/template/updategram.xml into your Web browser. This action will execute the updategram and store the data in the database. If the updategram executes successfully, the root XML element update will be returned. If an error occurred, XML processing instructions will be returned to indicate the error. (See Exploring XML, November 2001, for a description of error processing.)

Parameterized updategrams. Using a parameterized updategram to update the database would be quite convenient, especially to post data from an HTML Web page. However, a problem exists in the updategram processor. Parameterized updategrams pass parameters the same way XML templates pass them. The updategram processor constructs parameterized queries and submits the query to the database along with a collection of parameters. But the updategram processor treats all parameters as strings, thereby overriding the conversion logic that the mapping schema specified. A data-conversion error from the query processor results.

Unfortunately, you can't currently modify this behavior. Until Microsoft introduces data types to updategrams and templates, you can work around this problem by avoiding parameterized updategrams for binary data types. Listing 6, page 67, shows a Web page that uses Dynamic HTML (DHTML) to build an updategram when a user presses the Add Data button on the page. This code uses JavaScript to collect data from the HTML form and dynamically insert the data into the updategram. The updategram is then assigned to a hidden form element named template. When a user presses the Add Data button, the form values post to the virtual root, and the updategram is processed. To run this program, configure the virtual root to accept template= URL queries and Allow posted updategrams because the browser will post the updategram as a named parameter corresponding to the name of the hidden field (template). To configure this setting, use the Settings tab in the IIS Virtual Directory Management for SQL Server 2.0 snap-in that's installed with WR2. (See the WR2 documentation for more information about parameterized updategrams.)

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

 
 

ADS BY GOOGLE