public int Modificacion(Pago p) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"UPDATE Pagos SET Monto={p.Monto} , Pagado={p.Pagado}, Fecha='{p.Fecha}', NroPago={p.NroPago}, IdContrato={p.IdContrato} " + $"WHERE IdPago = {p.IdPago} ;"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); connection.Close(); } } return(res); }
public int Alta(Pago p) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Pagos (Monto, Pagado, Fecha, NroPago, EstadoPago, IdContrato) " + $"VALUES ({p.Monto}, {p.Pagado}, '{p.Fecha}', {p.NroPago}, 1, {p.IdContrato}) ;"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); command.CommandText = "SELECT SCOPE_IDENTITY()"; var id = command.ExecuteScalar(); p.IdPago = Convert.ToInt32(id); connection.Close(); } } return(res); }