コード例 #1
0
 public static void UpdatePenalty(Penalty penalty)
 {
     using (SqlConnection connection = new SqlConnection(ConnectionString))
     {
         connection.Open();
         using (SqlTransaction transaction = connection.BeginTransaction())
         using (SqlCommand command = new SqlCommand("UPDATE Penalty SET Description = @Description, Mode = @Mode, Value = @Value WHERE PenaltyId = @PenaltyId", connection, transaction))
         {
             try
             {
                 command.Parameters.Add("@Description", SqlDbType.VarChar).Value = penalty.Description;
                 command.Parameters.Add("@Mode", SqlDbType.Int).Value = penalty.Mode;
                 command.Parameters.Add("@Value", SqlDbType.Int).Value = penalty.Value;
                 command.Parameters.Add("@PenaltyId", SqlDbType.Int).Value = penalty.PenaltyID;
                 command.ExecuteNonQuery();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
コード例 #2
0
 public static void AddPenalty(int eventId, Penalty penalty)
 {
     using (SqlConnection connection = new SqlConnection(ConnectionString))
     {
         connection.Open();
         using (SqlTransaction transaction = connection.BeginTransaction())
         using (SqlCommand command = new SqlCommand("INSERT INTO Penalty(EventId, Description, Mode, Value) Values(@EventId, @Description, @Mode, @Value)", connection, transaction))
         {
             try
             {
                 command.Parameters.Add("@EventId", SqlDbType.Int).Value = penalty.EventID;
                 command.Parameters.Add("@Description", SqlDbType.VarChar).Value = penalty.Description;
                 command.Parameters.Add("@Mode", SqlDbType.Int).Value = penalty.Mode;
                 command.Parameters.Add("@Value", SqlDbType.Int).Value = penalty.Value;
                 command.ExecuteNonQuery();
             }
             catch (Exception)
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }