tailieunhanh - Updating Server Data Using a Web Service

[ Team LiB ] Recipe Updating Server Data Using a Web Service Problem You want to update a data source using an XML web service and use the web service from your client application. Solution Use a DataSet object. The XML web service code contains two methods: LoadOrders( ) | Team LiB Recipe Updating Server Data Using a Web Service Problem You want to update a data source using an XML web service and use the web service from your client application. Solution Use a DataSet object. The XML web service code contains two methods LoadOrders Creates and returns a DataSet containing the Orders and Order Details tables from Northwind and a DataRelation between those tables. UpdateOrders Takes a DataSet argument containing the changes made to the DataSet created by the LoadOrders method creates two DataAdapter objects with CommandBuilder generated update logic for each and uses the DataAdapter objects to update the Orders and Order Details tables in Northwind. The client-side code contains two event handlers Sets up the example by calling the LoadOrders method in the web service to populate a DataSet. The default view of the Orders table is bound to the data grid on the form. Update Calls the UpdateOrders method in the web service passing a DataSet containing changes made to the DataSet since the form was loaded or since the last time the UpdateOrders method was called. The C code for the XML web service is shown in Example 4-25. Example 4-25. File Namespaces variables and constants using System using using using using using public const String ORDERS_TABLE Orders public const String ORDERDETAILS_TABLE OrderDetails public const String ORDERID_FIELD OrderlD public const String ORDERS_ORDERDETAILS_RELATION Order_OrderDetails_Relation . . . WebMethod public DataSet LoadOrders DataSet ds new DataSet SqlDataAdapter da Fill the Order table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Orders DataConnectString DataTable orderTable new DataTable ORDERS_TABLE orderTable orderTable orderTable Fill the .