• 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         }
  • 相关阅读:
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化和保存
    爬取全部校园新闻
    爬取校园新闻
    Google布隆过滤器
    谷歌json和对象转换
    postgresql和postgis
    json和实体类互相转换
    Linux安装docker-compose
  • 原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/15826109.html
Copyright © 2020-2023  润新知