Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Populate DropDownList in C#

Options
  • 17-01-2008 3: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 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