The following code demonstrates how to use DataSet + dataAdapter to operate the background database and provides transaction processing.
Code
1 using System;
2 using System. Web. Services;
3 using System. Data;
4 using System. Data. OleDb;
5
6 namespace TransactionTest
7 {
8 /// <summary>
9 // Service1 Summary
10 /// </summary>
11 [WebService (Namespace = "http://tempuri.org/")]
12 [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
13 [System. ComponentModel. ToolboxItem (false)]
14 // to allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
15 // [System. Web. Script. Services. ScriptService]
16 public class TransWsTest: System. Web. Services. WebService
17 {
18 // Private attributes
19 private OleDbConnection _ DBConn;
20 private OleDbTransaction _ DBTrans;
21
22 [WebMethod]
23 public string HelloWorld ()
24 {
25 _ DBConn. Close ();
26 return "Hello World ";
27}
28
29 [WebMethod]
30 public string TransTest_Insert ()
31 {
32 try
33 {
34
35 InsertData ("Ma Kan", "R & D department ");
36 InsertData ("Li Wei", "R & D department ");
37 // InsertData ("Ma Kan", "R & D department ");
38