//执行多条语句,实现事务。

        public  void ExecuteSqlTran(ArrayList SQLStringList)
        {
         
            SqlConnection cn = this.getcon();
            cn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            SqlTransaction tx = cn.BeginTransaction();
            cmd.Transaction = tx;
            try
            {
                for (int i = 0; i < SQLStringList.Count; i++)
                {
                    string strSQL = SQLStringList[i].ToString();
                    if (strSQL.Trim().Length > 1)
                    {
                        cmd.CommandText = strSQL;
                        cmd.ExecuteNonQuery();
                    }
                }
                tx.Commit();
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                tx.Rollback();
                throw new Exception(e.Message);
            }

        }

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2021-10-07
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案