static List <County> HotCountiesQuery(String queryString, int n) { string connectionString = "Data Source=(local);Initial Catalog=H19;" + "Integrated Security=true"; List <County> hotCounties = new List <County>(); // Create and open the connection in a using block. using (SqlConnection connection = new SqlConnection(connectionString)) { // Create the Command and Parameter objects. SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.Add("@topNumber", SqlDbType.Int); command.Parameters["@topNumber"].Value = n; // Open the connection in a try/catch block. try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { County temp = new County((string)reader[1], (int)reader[2]); temp.Samples.Add(new CaseDatum(Convert.ToDateTime(reader[0]), (int)reader[3])); hotCounties.Add(temp); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } int count = 0; foreach (County element in hotCounties) { count++; Console.WriteLine($"No.#{count} hottest county: {element.name}"); } return(hotCounties); }
static County TimeQueryHelper(String countyName, String queryString) { string connectionString = "Data Source=(local);Initial Catalog=H19;" + "Integrated Security=true"; County temp = new County(); // Create and open the connection in a using block. using (SqlConnection connection = new SqlConnection(connectionString)) { // Create the Command and Parameter objects. SqlCommand command = new SqlCommand(queryString, connection); // Open the connection in a try/catch block. try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (temp.name == null) { temp.name = (String)reader[1]; temp.population = (int)reader[3]; } temp.Samples.Add(new CaseDatum(Convert.ToDateTime(reader[0]), (int)reader[4])); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine($"{countyName} Time Series"); foreach (CaseDatum element in temp.Samples) { Console.WriteLine($"Date: {element.when.ToString("d", CultureInfo.CreateSpecificCulture("en-US"))} Cases: {element.cases}"); } return(temp); }