Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Populate DropDownList in C#

  • 17-01-2008 03:56PM
    #1
    Closed Accounts Posts: 10


    I am trying to populate a dropdownlist from MySql DB depending on what value is in a label.
    The information will be coming from two different tables (Team)and(Player) i.e depending on what team is put into the label, player names will load into the dropdownlist.

    I know that I will need to use foreign keys but is it possible to write a query using the value in a label?

    I was thinking something like "select * from player where teamID = (select teamID from team where TeamName = "label.text" )"

    Any suggestions greatly appreciated!


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Are the team names unique? You could use something like
    Select p.* from player p 
    inner join team t on 
    p.TeamID = t.TeamID
    where t.Name = [i]'teamname'[/i]
    

    teamname being the text being supplied.

    However, whats to stop you having two dropdowns, one containing all the teams and one containing all the players. So a team is selected and all the players for that team are populated into the players dropdown. That would be the basis for more robust solution.


Advertisement