public Car UpdateCar(Car car)
{
try
{
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand command = con.CreateCommand())
{
command.CommandText = "UPDATE Car SET Title = @Title, Price = @Price, Miles = @Miles, Status = @Status WHERE Id = @Id";
command.Parameters.AddWithValue("@Id", car.Id);
command.Parameters.AddWithValue("@Title", car.Title ?? "");
command.Parameters.AddWithValue("@Price", car.Price ?? 0);
command.Parameters.AddWithValue("@Miles", car.Miles ?? 0);
command.Parameters.AddWithValue("@Status", car.Status ?? "");
command.ExecuteNonQuery();
}
con.Close();
return car;
}
}
catch (Exception ex)
{
// Handle the exception if needed
throw;
}
}
public Car UpdateCar(Car car)
{
try
{
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand command = con.CreateCommand())
{
command.CommandText = "UPDATE Car SET Title = @Title, Price = @Price, Miles = @Miles, Status = @Status WHERE Id = @Id";
command.Parameters.AddWithValue("@Id", car.Id);
command.Parameters.AddWithValue("@Title", car.Title ?? "");
command.Parameters.AddWithValue("@Price", car.Price ?? 0);
command.Parameters.AddWithValue("@Miles", car.Miles ?? 0);
command.Parameters.AddWithValue("@Status", car.Status ?? "");
command.ExecuteNonQuery();
}
con.Close();
return car;
}
}
catch (Exception ex)
{
// Handle the exception if needed
throw;
}
}