WeatherForecastController.cs 1.0 KB

123456789101112131415161718192021222324252627282930
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Data.SqlClient;
  3. namespace WebApplication1.Controllers
  4. {
  5. [ApiController]
  6. [Route("[controller]")]
  7. public class WeatherForecastController : ControllerBase
  8. {
  9. static public SqlConnection SqlConnection = new SqlConnection("Data Source=ngknn.ru;Initial Catalog=AAAnobldemo;User ID=21p;Password=12357;Connect Timeout=30;Encrypt=False;Trust Server Certificate=True;Application Intent=ReadWrite;Multi Subnet Failover=False");
  10. [HttpGet(Name = "GetWeatherForecast")]
  11. public List<string> GetRegion()
  12. {
  13. SqlConnection.Open();
  14. SqlCommand sqlCommand = new SqlCommand("select NameRegion from Region", SqlConnection);
  15. List<string> list = new List<string>();
  16. SqlDataReader reader = sqlCommand.ExecuteReader();
  17. while (reader.Read())
  18. {
  19. list.Add(reader.GetString(0));
  20. }
  21. SqlConnection.Close();
  22. reader.Close();
  23. return list;
  24. }
  25. }
  26. }