예제 #1
0
        public static Team GetTeam(int teamID)
        {
            DataTable teamData = new DataTable();
            string sql = @"select TeamID, LeagueID, TeamName
                            from Teams
                            where TeamID = @TeamID";

            using (SqlConnection conn = new SqlConnection(Main.GetDSN()))
            {
                SqlCommand command = new SqlCommand(sql, conn);
                command.Parameters.AddWithValue("@TeamID", teamID);
                new SqlDataAdapter(command).Fill(teamData);
            }

            Team team = new Team();
            team.TeamID = Convert.ToInt32(teamData.Rows[0]["TeamID"]);
            team.LeagueID = Convert.ToInt32(teamData.Rows[0]["LeagueID"]);
            team.TeamName = teamData.Rows[0]["TeamName"].ToString();

            return team;
        }
예제 #2
0
        public static IEnumerable<Team> GetTeams(int leagueID)
        {
            DataTable teamData = new DataTable();
            string sql = @"select TeamID, LeagueID, TeamName
                            from Teams
                            where LeagueID = @LeagueID";

            using (SqlConnection conn = new SqlConnection(Main.GetDSN()))
            {
                SqlCommand command = new SqlCommand(sql, conn);
                command.Parameters.AddWithValue("@LeagueID", leagueID);
                new SqlDataAdapter(command).Fill(teamData);
            }

            List<Team> teams = new List<Team>();
            foreach (DataRow teamRow in teamData.Rows)
            {
                Team team = new Team();
                team.TeamID = Convert.ToInt32(teamRow["TeamID"]);
                team.LeagueID = Convert.ToInt32(teamRow["LeagueID"]);
                team.TeamName = teamRow["TeamName"].ToString();
                teams.Add(team);
            }

            return teams;
        }