[Introduction to DB Apps] Problem. Change Town Names Casing
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class InitialSetup
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection("Server=DESKTOP-281JNDE; Integrated security=true;");
connection.Open();
using (connection)
{
var country = Console.ReadLine();
string query = File.ReadAllText(@"../../getTowns.sql");
SqlCommand findTownsByCountryCommand = new SqlCommand(query, connection);
SqlParameter countryName = new SqlParameter("@Country", country);
findTownsByCountryCommand.Parameters.Add(countryName);
SqlDataReader reader = findTownsByCountryCommand.ExecuteReader();
if (!reader.Read())
{
Console.WriteLine("No town names were affected.");
return;
}
List<string> towns = new List<string>();
while (reader.Read())
{
string currentTown = (string)reader["townname"];
towns.Add(currentTown.ToUpper());
}
Console.WriteLine($"[{string.Join(",", towns)}]");
}
}
}
Не знам защо reader-a ми започва да взима стойностите от втората в базата и се получава, че при два записа в базата той ми взима втория, update-ва и не наммира първият, а при един запис не взима нищо...
Eто ми е заявката
USE MinionsDB
SELECT TownName FROM Towns
WHERE CountryName = @Country