Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HW01_5_ChangeTownNamesCasing
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Request country name
- string countryName = Console.ReadLine();
- // Connect to SQL
- using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MinionsDB;Integrated Security=True"))
- {
- conn.Open();
- // Read SQL query from file
- string q1 = File.ReadAllText(@"..\..\HW01-5-ChangeTownNamesCasing.sql");
- // Construct command & params
- using (SqlCommand cmd = new SqlCommand(q1, conn)) {
- cmd.Parameters.AddWithValue("@CountryName", countryName);
- // Execute query and get output
- using (SqlDataReader dr = cmd.ExecuteReader()) {
- List<string> changed = new List<string>();
- while (dr.Read()) {
- changed.Add((string)dr["Name"]);
- }
- if (changed.Count > 0)
- {
- Console.WriteLine($"{changed.Count} town names were affected.\r\n{String.Join(", ", changed)}");
- }
- else {
- Console.WriteLine("No town names were affected.");
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement