antony--异域空间
性格左右命运,气度影响格局!

 

/// <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;
                    }

                }
                
            }

        }
posted on 2008-06-17 16:47  antony.net  阅读(947)  评论(0编辑  收藏  举报