Đang chuẩn bị liên kết để tải về tài liệu:
Updating Server Data Using a Web Service
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
[ Team LiB ] Recipe 4.11 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 4.11 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 Form.Load 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 Button.Click 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 NorthwindServiceCS.asmx.es Namespaces variables and constants using System using System.ComponentModel using System.Web.Services using System.Configuration using System.Data using System.Data.SqlClient 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 ConfigurationSettings.AppSettings DataConnectString DataTable orderTable new DataTable ORDERS_TABLE da.FillSchema orderTable SchemaType.Source da.Fill orderTable ds.Tables.Add orderTable Fill the .