Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. [Route("api/cities/")]
  2. public IHttpActionResult GetCitiesNames()
  3. {
  4. List<String> list = new List<String>();
  5. SqlConnection conn = new SqlConnection(CONNSTRING);
  6. conn.Open();
  7. SqlCommand cmd = new SqlCommand("SELECT DISTINCT(city) FROM Data", conn);
  8.  
  9. SqlDataReader reader = cmd.ExecuteReader();
  10.  
  11. while (reader.Read())
  12. {
  13.  
  14. list.Add(reader["city"].ToString());
  15. }
  16.  
  17. if (list.Count <= 0)
  18. {
  19. reader.Close();
  20. conn.Close();
  21. return NotFound();
  22. }
  23.  
  24. reader.Close();
  25. conn.Close();
  26. return Ok(list);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement