zoukankan      html  css  js  c++  java
  • C#使用事务

            

             /// <summary>
            /// 执行多条SQL语句,实现数据库事务。
            /// </summary>
            /// <param name="SQLStringList">多条SQL语句</param>  
            public static int ExecuteSqlTran(List<String> SQLStringList)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = connection;
                    SqlTransaction tx = connection.BeginTransaction();
                    cmd.Transaction = tx;
                    try
                    {
                        int count = 0;
                        for (int n = 0; n < SQLStringList.Count; n++)
                        {
                            string strsql = SQLStringList[n];
                            if (strsql.Trim().Length > 1)
                            {
                                cmd.CommandText = strsql;
                                count += cmd.ExecuteNonQuery();
                            }
                        }
                        tx.Commit();
                        return count;
                    }
                    catch
                    {
                        tx.Rollback();
                        return 0;
                    }
                    finally
                    {
                        cmd.Dispose();
                        connection.Close();
                    }
                }
            }

  • 相关阅读:
    PHP XML Expat 解析器
    处理get请求中特殊字符的处理
    bootstrap模态框隐藏事件
    HTML中tr是什么?
    php 日期正则表达式
    # JavaScript中的对象
    python发送get请求
    PHP格式化MYSQL返回float类型的方法
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/paste/p/1969982.html
Copyright © 2011-2022 走看看