///<summary>
///.net万能事务
///</summary>
///<param name="cmdtext1">第一个存储过程或者sql语句;</param>
///<param name="cmdtext2">第二个存储过程或者sql语句;</param>
///<param name="para1">第一个存储过程或者sql的参数</param>
///<param name="para2">第二个存储过程或者sql的参数</param>
///<param name="ct1">第一个参数的类型(存储过程或者sql)</param>
///<param name="ct2">第二个参数的类型(存储过程或者sql)</param>
public static int procAffairs(string cmdtext1, string cmdtext2, SqlParameter[] para1, SqlParameter[] para2, CommandType ct1,CommandType ct2)
{
using (SqlConnection conn = GetConnection())
{
SqlTransaction tran;
//SqlCommand cmd;
SqlCommand cmd = new SqlCommand();
try
{
conn.Open();
tran = conn.BeginTransaction();
cmd.Transaction = tran;
cmd.Connection = conn;
//cmd = new SqlCommand(cmdtext1, conn);
cmd.CommandText = cmdtext1;
cmd.CommandType = ct1;
cmd.Parameters.AddRange(para1);
cmd.ExecuteNonQuery();
//cmd = new SqlCommand(cmdtext2, conn);
cmd.CommandText = cmdtext2;
cmd.CommandType = ct2;
cmd.Parameters.AddRange(para2);
cmd.ExecuteNonQuery();
cmd = new SqlCommand();
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
return 0;
}
}
return 1;
}
翻过高山走不出你
慕村9548890
牛魔王的故事
撒科打诨
慕丝7291255