• 执行多条SQL语句,实现数据库事务。


    /// <summary>
            
    /// 执行多条SQL语句,实现数据库事务。
            
    /// </summary>
            
    /// <param name="SQLStringList">SQL语句的哈希表(key为sql语句,value是该语句的SqlParameter[])</param>

            public  void ExecuteSqlTran(Hashtable SQLStringList)
            
    {            
                
    using (SqlConnection conn=new SqlConnection(this.ConnectionString))
                
    {
                    conn.Open();
                    
    using (SqlTransaction trans = conn.BeginTransaction()) 
                    
    {
                        
                        
    try 
                        
    {
                            
    //循环
                            foreach (DictionaryEntry myDE in SQLStringList)
                            
    {    
                                SqlCommand cmd 
    = new SqlCommand();
                                
    string[] tmp = myDE.Key.ToString ().Split(new char[] '|' });
                                
    string     cmdText=tmp[1];
                                SqlParameter[] cmdParms
    =(SqlParameter[])myDE.Value;
                                PrepareCommand(cmd,conn,trans,cmdText, cmdParms);
                                
    int val = cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();

                                
                            }

                            trans.Commit();
                        }

                        
    catch
                        
    {                    
                            trans.Rollback();
                            
    throw;
                        }

                    }
                    
                }

            }
    antony
    :antony1029@163.com
    :http://antony1029.cnblogs.com
  • 相关阅读:
    pidgin的未认证解决办法
    题解【洛谷P1074】[NOIP2009]靶形数独
    题解【洛谷P1315】[NOIP2011]观光公交
    题解【BZOJ4145】「AMPPZ2014」The Prices
    题解【洛谷P4588】[TJOI2018]数学计算
    题解【洛谷P3884】[JLOI2009]二叉树问题
    题解【SP8002】HORRIBLE
    树链剖分学习笔记
    题解【洛谷P1807】最长路_NOI导刊2010提高(07)
    题解【洛谷P1995】口袋的天空
  • 原文地址:https://www.cnblogs.com/antony1029/p/1224124.html
Copyright © 2020-2023  润新知