zoukankan      html  css  js  c++  java
  • C# 事务处理

    /// <summary>
            /// 多SQL语句操作--事务处理
            /// </summary>
            /// <param name="sqlComm">SQL语句数组</param>
            /// <returns>事务,返回String事务结果</returns>
            public string DoTran(string[] sqlComm)
            {
                if (connection.State.ToString() == "Closed")
                    connection.Open();
                SqlTransaction myTran;
                myTran = connection.BeginTransaction();
                //string mess;
                
                SqlCommand command = new SqlCommand("",connection,myTran);
                //command.Connection = connection;
                try
                {
                    foreach (string comm in sqlComm)
                    {
                        command.CommandText = comm;
                        command.ExecuteNonQuery();
                    }
                    myTran.Commit();
                }
                catch (Exception e)
                {
                    //throw new ApplicationException("系统信息:" + e.Message);
                    return e.Message;
                }
                finally
                {
                    connection.Close();
                }
                return "事务操作成功!";
            }
  • 相关阅读:
    第二十九课 循环链表的实现
    第二十八课 再论智能指针(下)
    第二十七课 再论智能指针(上)
    第二十六课 典型问题分析(Bugfix)
    普通new和placement new的重载
    leetcode 581. Shortest Unsorted Continuous Subarray
    leetcode 605. Can Place Flowers
    leetcode 219. Contains Duplicate II
    leetcode 283. Move Zeroes
    leetcode 217. Contains Duplicate
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1677340.html
Copyright © 2011-2022 走看看