Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace PokerData
  10. {
  11. public class PokerDb
  12. {
  13. public static SqlConnection GetConnection()
  14. {
  15. //string connectionString = "Data Source = 172.245.208.97;" + "User Id = fred;" + "Password = fred;" + "Initial Catalog = Poker;";
  16. //string connectionString = "Data Source=172.245.208.97; Initial Catalog=Poker;User=fred;Password=fred;Integrated Security=False";
  17. string connectionString = "server=172.245.208.97;database=Poker;user=fred;password=fred;";
  18.  
  19. return new SqlConnection(connectionString);
  20. }
  21.  
  22. public static List<Player> GetPlayers()
  23. {
  24. SqlDataReader reader = null;
  25. List<Player> playerList = new List<Player>();
  26. SqlConnection connection = GetConnection();
  27. string selectStatement =
  28. "SELECT Naam, Bedrag " +
  29. "FROM Players " +
  30. "ORDER BY Bedrag DESC";
  31. SqlCommand selectCommand = new SqlCommand(selectStatement, connection);
  32. try
  33. {
  34. connection.Open();
  35. reader = selectCommand.ExecuteReader();
  36. while (reader.Read())
  37. {
  38. Player player = new Player();
  39. player.Naam = reader["Naam"].ToString();
  40. player.Bedrag = (double)reader["Bedrag"];
  41. playerList.Add(player);
  42. }
  43. }
  44. catch (IndexOutOfRangeException ex)
  45. {
  46. throw ex;
  47. }
  48. finally
  49. {
  50. if (reader != null)
  51. {
  52. reader.Close();
  53. }
  54. connection.Close();
  55. }
  56. return playerList;
  57. }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement