/// <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;
}
}
}
}
/// 执行多条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;
}
}
}
}