ADO.NET中使用事务

 using (SqlConnection conn = new SqlConnection(k2ConnStr))
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    cmd.Transaction = tran;
                    int result = Convert.ToInt32(cmd.ExecuteScalar());
                }
                catch (Exception)
                {
                    tran.Rollback();
                }

            }

 

posted @ 2019-09-27 15:59  冷瞳ruin  阅读(161)  评论(0编辑  收藏  举报