• MSSQL数据库事务


     1         /// <summary>
     2         /// 执行多条SQL语句,实现数据库事务。
     3         /// </summary>
     4         /// <param name="SQLStringList">多条SQL语句</param>        
     5         public static int ExecuteSqlTran(List<String> SQLStringList)
     6         {
     7             using (SqlConnection conn = new SqlConnection(connectionString))
     8             {
     9                 conn.Open();
    10                 SqlCommand cmd = new SqlCommand();
    11                 cmd.Connection = conn;
    12                 SqlTransaction tx = conn.BeginTransaction();
    13                 cmd.Transaction = tx;
    14                 try
    15                 {
    16                     int count = 0;
    17                     for (int n = 0; n < SQLStringList.Count; n++)
    18                     {
    19                         string strsql = SQLStringList[n];
    20                         if (strsql.Trim().Length > 1)
    21                         {
    22                             cmd.CommandText = strsql;
    23                             count += cmd.ExecuteNonQuery();
    24                         }
    25                     }
    26                     tx.Commit();
    27                     return count;
    28                 }
    29                 catch
    30                 {
    31                     tx.Rollback();
    32                     return 0;
    33                 }
    34             }
    35         }
  • 相关阅读:
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    Alpha 冲刺 (5/10)
    团队现场编程实战(抽奖系统)
    Alpha 冲刺 (4/10)
    斗地主
    解方程
    货币系统
  • 原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/15826109.html
Copyright © 2020-2023  润新知