首页 > 其他分享 >TransactionScope

TransactionScope

时间:2023-08-25 14:46:33浏览次数:43  
标签:INSERT ExecuteSql INTO TransactionScope user password id

 

using System.Transactions;



            using (TransactionScope scope =
                new TransactionScope(TransactionScopeOption.Required,
                   new TransactionOptions
                   {
                       IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                       Timeout = new TimeSpan(0, 0, 120)
                   })
               )
            {
              try

              {

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789');");

                  ExecuteSql("delete from  [user] where id=5;");

                  ExecuteSql(

                      "INSERT INTO [user]([id], [name], [age], [password]) VALUES (5, N'zhaoliu', 17, '789',123);");//错误方法

                  scope.Complete();

              }

              catch (Exception ex)

              {

 

                  Console.WriteLine(ex);

              }
            }

 

标签:INSERT,ExecuteSql,INTO,TransactionScope,user,password,id
From: https://www.cnblogs.com/myloveblogs/p/17656854.html

相关文章