// Get the player names for display in GridView private List<Player> GetPlayerNames() { //command.Connection = connection; //command.CommandType = CommandType.StoredProcedure; //command.CommandText = "GetTeamPlayers"; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Player player = new Player() { PlayerId = Convert.ToInt32(reader["PlayerId"]), PlayerName = reader["PlayerName"].ToString(), TeamId = Convert.ToInt32(reader["TeamId"]) }; players.Add(player); } reader.Close(); connection.Close(); return players; }
private List<Player> GetTeamPlayers(int teamId) { List<Player> players = new List<Player>(); connection.Open(); command.Connection = connection; command.Parameters.Clear(); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@TeamId", teamId); command.CommandText = "GetTeamPlayers"; var reader = command.ExecuteReader(); while (reader.Read()) { Player player = new Player() { PlayerId = Convert.ToInt32(reader["PlayerId"]), PlayerName = reader["PlayerName"].ToString() }; players.Add(player); } reader.Close(); connection.Close(); return players; }