日期:2014-05-18 浏览次数:20688 次
using (SqlConnection Conn = new SqlConnection(connectString)) { Conn.Open(); using (SqlTransaction Tran = Conn.BeginTransaction()) { using (SqlCommand Comm = new SqlCommand() { Connection = Conn, Transaction = Tran }) { try { Comm.CommandType = CommandType.StoredProcedure; Comm.CommandText = "存储过程1"; Comm.Parameters.AddRange(MaParas(order)); Comm.ExecuteNonQuery(); Comm.CommandType = CommandType.StoredProcedure; Comm.CommandText = "存储过程2"; for (int i = 0; i < ModelList.Count; i++) { Comm.Parameters.Clear(); Comm.Parameters.AddRange(LbParas(ModelList[i])); Comm.ExecuteNonQuery(); } Tran.Commit(); } catch (Exception ex) { Tran.Rollback(); } } } }