public static void ListAvailableCars() { Console.Clear(); string conString = "Data Source=DESKTOP-MJA5A7T;Initial Catalog=Car Rent;Integrated Security=True"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter("select Cars.CarID,Plate, Model, Manufacturer, PricePerDay, Reservations.Location from Cars join Reservations on Cars.CarID=Reservations.CarID", con); DataTable dt = new DataTable(); dataAdapter.Fill(dt); Console.WriteLine("Start date:"); string startDate = ""; while (startDate == "") { startDate = Console.ReadLine(); if (!(Register_New_Rent.DataValidation(startDate))) { Console.WriteLine("Invalid data"); } } Console.WriteLine("End Date:"); string endDate = ""; while (endDate == "") { endDate = Console.ReadLine(); if (!(Register_New_Rent.DataValidation(endDate))) { Console.WriteLine("Invalid data"); } } DisplayListAvailableCars(dt, startDate, endDate, con); int column = 0; int prevColumn = 0; while (true) { column = int.Parse(Console.ReadLine()); if (column == prevColumn) { switch (column) { case 1: dt = OrderBy.OrderByCarIDDesc(dt); break; case 2: dt = OrderBy.OrderByPlateDesc(dt); break; case 3: dt = OrderBy.OrderByManufacturerDesc(dt); break; case 4: dt = OrderBy.OrderByModelDesc(dt); break; case 5: dt = OrderBy.OrderByPricePerDayDesc(dt); break; case 6: dt = OrderBy.OrderByLocationDesc(dt); break; } } else { switch (column) { case 1: dt = OrderBy.OrderByCarID(dt); break; case 2: dt = OrderBy.OrderByPlate(dt); break; case 3: dt = OrderBy.OrderByManufacturer(dt); break; case 4: dt = OrderBy.OrderByModel(dt); break; case 5: dt = OrderBy.OrderByPricePerDay(dt); break; case 6: dt = OrderBy.OrderByLocation(dt); break; default: dt = OrderBy.OrderByCarID(dt); break; } } prevColumn = column; DisplayListAvailableCars(dt, startDate, endDate, con); } }