Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySql.Data.MySqlClient;
- namespace PokerData
- {
- public class PokerDb
- {
- public static SqlConnection GetConnection()
- {
- //string connectionString = "Data Source = 172.245.208.97;" + "User Id = fred;" + "Password = fred;" + "Initial Catalog = Poker;";
- //string connectionString = "Data Source=172.245.208.97; Initial Catalog=Poker;User=fred;Password=fred;Integrated Security=False";
- string connectionString = "server=172.245.208.97;database=Poker;user=fred;password=fred;";
- return new SqlConnection(connectionString);
- }
- public static List<Player> GetPlayers()
- {
- SqlDataReader reader = null;
- List<Player> playerList = new List<Player>();
- SqlConnection connection = GetConnection();
- string selectStatement =
- "SELECT Naam, Bedrag " +
- "FROM Players " +
- "ORDER BY Bedrag DESC";
- SqlCommand selectCommand = new SqlCommand(selectStatement, connection);
- try
- {
- connection.Open();
- reader = selectCommand.ExecuteReader();
- while (reader.Read())
- {
- Player player = new Player();
- player.Naam = reader["Naam"].ToString();
- player.Bedrag = (double)reader["Bedrag"];
- playerList.Add(player);
- }
- }
- catch (IndexOutOfRangeException ex)
- {
- throw ex;
- }
- finally
- {
- if (reader != null)
- {
- reader.Close();
- }
- connection.Close();
- }
- return playerList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement