Exemplo n.º 1
0
 public int Modificacion(Pago p)
 {
     int res = -1;
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string sql = "UPDATE Pagos " +
             $"SET Nro = @Nro, Fecha = @fecha, Importe = @importe, IdContrato = @idContrato " +
             $"WHERE Id = @id";
         using (SqlCommand command = new SqlCommand(sql, connection))
         {
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@id", p.Id);
             command.Parameters.AddWithValue("@Nro", p.Nro);
             command.Parameters.AddWithValue("@fecha", p.Fecha);
             command.Parameters.AddWithValue("@importe", p.Importe);
             command.Parameters.AddWithValue("@idContrato", p.IdContrato);
             connection.Open();
             res = command.ExecuteNonQuery();
             connection.Close();
         }
     }
     return res;
 }
Exemplo n.º 2
0
 public int Alta(Pago p)
 {
     int res = -1;
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string sql = "INSERT INTO Pagos (Nro, Fecha, Importe, IdContrato) " +
             "VALUES (@Numero, @Fecha, @Importe, @IdContrato);" +
             "SELECT SCOPE_IDENTITY();";
         using (SqlCommand command = new SqlCommand(sql, connection))
         {
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@numero", p.Nro);
             command.Parameters.AddWithValue("@fecha", p.Fecha);
             command.Parameters.AddWithValue("@importe", p.Importe);
             command.Parameters.AddWithValue("@idContrato", p.IdContrato);
             connection.Open();
             res = Convert.ToInt32(command.ExecuteScalar());
             p.Id = res;
             connection.Close();
         }
     }
     return res;
 }