Advertisement
Guest User

Untitled

a guest
Feb 9th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using Npgsql;
  3. using NpgsqlTypes;
  4. using System.Collections.Generic;
  5.  
  6. namespace Project1
  7. {
  8. class MainClass
  9. {
  10. public static void Main (string[] args)
  11. {
  12. DBManagement db = new DBManagement();
  13. db.getStates ();
  14. Console.WriteLine ("Please enter a State from the following list:");
  15. db.printStates ();
  16. string userState = Console.ReadLine();
  17. }
  18. }
  19.  
  20. public class DBManagement
  21. {
  22. List<string> statelist = new List<string>();
  23. public void getStates()
  24. {
  25. using (var conn = new NpgsqlConnection("Host=localhost; Username=admin; Password=D3c1@nair#; Database=Milestone1DB"))
  26. {
  27. conn.Open ();
  28. using (var cmd = new NpgsqlCommand ())
  29. {
  30. cmd.Connection = conn;
  31. cmd.CommandText = "SELECT DISTINCT state FROM business ORDER BY state";
  32. using(var reader = cmd.ExecuteReader())
  33. {
  34. while (reader.Read())
  35. {
  36. statelist.Add(reader.GetString(0));
  37. }
  38. }
  39. }
  40. conn.Close();
  41. }
  42. }
  43. public void printStates()
  44. {
  45. foreach (string state in statelist)
  46. {
  47. Console.Write(state + " ");
  48. }
  49. Console.WriteLine ("");
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement