public static void ListCustomers() { 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 * from Customers", con); DataTable dt = new DataTable(); dataAdapter.Fill(dt); DisplayListCustomers(dt); int column = 0; int prevColumn = 0; while (true) { column = int.Parse(Console.ReadLine()); if (column == prevColumn) { switch (column) { case 1: dt = OrderBy.OrderByCustomerIdDesc(dt); break; case 2: dt = OrderBy.OrderByNameDesc(dt); break; case 3: dt = OrderBy.OrderByBirthDateDesc(dt); break; case 4: dt = OrderBy.OrderByLocationDesc(dt); break; } } else { switch (column) { case 1: dt = OrderBy.OrderByCustomerId(dt); break; case 2: dt = OrderBy.OrderByName(dt); break; case 3: dt = OrderBy.OrderByBirthDate(dt); break; case 4: dt = OrderBy.OrderByLocation(dt); break; default: dt = OrderBy.OrderByCustomerId(dt); break; } } prevColumn = column; DisplayListCustomers(dt); } }