日期:2014-05-18 浏览次数:20453 次
using System.Configuration; using System.Data.SqlClient; namespace SZTZ.BLL { public class Transactions { public static bool Tran1(SZTZ.Model.HDXXB mhd)//用来素质拓展办公室审核活动时 { string connectionString = ConfigurationManager.ConnectionStrings["menu"].ConnectionString; string sql1 = "update HDXXB set SHZT=@shzt,SZSHYJ=@szshyj,SZSHSJ=@szshsj where HDBH=@hdbh"; string sql2 = ""; if(mhd.CYFS==1||mhd.CYFS==4||mhd.CYFS==0)//院级活动,校级直接参加活动 { //为申报单位增加一条发布信息 FBZT 1表示为自己未发布 因为不存在上级发布 sql2 = "insert HDFBB(HDBH,JGBH,FBZT) values(@hdbh,@sbjg,1)"; } if (mhd.CYFS == 2 || mhd.CYFS == 3)//校级逐级活动 是需要逐级发布的 { //不考虑存在院级限制,每个院增加一条信息, sql2 = "EXEC hdfb @hdbh,@sbjg";//执行存储过程 hfbb(活动编号,申报单位) } using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd1 = new SqlCommand(); cmd1.Connection = con; cmd1.CommandText = sql1; cmd1.Parameters.AddWithValue("shzt",mhd.SHZT); cmd1.Parameters.AddWithValue("szshyj",mhd.SZSHYJ); cmd1.Parameters.AddWithValue("szshsj", mhd.SJSHSJ); cmd1.Parameters.AddWithValue("hdbh",mhd.HDBH); SqlCommand cmd2 = new SqlCommand(); cmd2.Connection = con; cmd2.CommandText = sql2; cmd2.Parameters.AddWithValue("hdbh",mhd.HDBH); cmd2.Parameters.AddWithValue("sbjg",mhd.SBJG); con.Open(); SqlTransaction tran = con.BeginTransaction(); cmd1.Transaction = tran; cmd2.Transaction = tran; try { cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); tran.Commit(); return true; } catch (System.Exception ex) { tran.Rollback(); return false; } } } public static bool ss() { return false; } } }
cmd1.Parameters.AddWithValue("shzt",mhd.SHZT); cmd1.Parameters.AddWithValue("szshyj",mhd.SZSHYJ); cmd1.Parameters.AddWithValue("szshsj", mhd.SJSHSJ); cmd1.Parameters.AddWithValue("hdbh",mhd.HDBH); //给变量赋值,你的变量写的不对吧? cmd1.Parameters.AddWithValue("@shzt",mhd.SHZT); cmd1.Parameters.AddWithValue("@szshyj",mhd.SZSHYJ); cmd1.Parameters.AddWithValue("@szshsj", mhd.SJSHSJ); cmd1.Parameters.AddWithValue("@hdbh",mhd.HDBH);