title: How Do I Populate Text Boxes With Sql Database Data Using One Combo Box
body: <p>Hey everyone pretty new to SQL Database functions but have been coding in c# for about a year now still not that great at it but I'm getting there! </p>
  
  <p>I'm currently creating a football application and to Edit players and Matches i was wanting to use one drop down combo box to retrieve data from an SQL database which then would populate other text boxes and combo boxes. I've had a go at it myself but don't know where i'm going wrong.</p>
  
  <p>On form load my connection opens i populate my datasets and  i execute this method to populate my combobox</p>
  
  <pre><code>private void Navigate()
  {
     string showPlayers = "SELECT * From Add_Players";
     SqlCommand cmdData = new SqlCommand(showPlayers, conn);
     SqlDataReader myReader = cmdData.ExecuteReader();
  
     while (myReader.Read())
     {
        comboEditPlayer.Items.Add(myReader[0]);
     }
     conn.Close();
  }
  </code></pre>
  
  <p>After which in the combo box selected index changed method i have this code </p>
  
  <pre><code>private void comboEditPlayer_SelectedIndexChanged(object sender, EventArgs e)
  {
     try
     {
        conn.Open();
        string showPlayers = "SELECT * From Add_Players WHERE Player_ID ='" 
        + comboEditPlayer + "'   ;";
        SqlCommand cmdData = new SqlCommand(showPlayers, conn);
        SqlDataReader myReader = cmdData.ExecuteReader();
  
        while (myReader.Read())
        {
           comboEditPlayerPos.Items.Add(myReader[1]);
           txtEditPlayerName.Text = myReader[2].ToString();
           txtEditPlayerSecond.Text = myReader[3].ToString();
           comboEditPlayerStatus.Items.Add(myReader[4]);
        }
        conn.Close();
        conn.Dispose();
     } 
     catch (Exception comboFail)
     {
        MessageBox.Show(comboFail.ToString());
     }
  }
  </code></pre>
  
  <p>I've been told this code is open and i need to use parameterized queries for preventing hacker attempts which i have started but do not know what Parameter i should be adding to the code i have for this is below </p>
  
  <pre><code>private void comboEditPlayer_SelectedIndexChanged(object sender, EventArgs e)
  {
     string connectionString =
        ZimbFootball.Properties.Settings.Default.Football2ConnectionString;
     using (SqlConnection connection = new SqlConnection (connectionString))
     {
        connection.Open();
  
        using (SqlCommand command = new SqlCommand(
                 "SELECT * From Add_Players WHERE Player_ID =" 
                 + comboEditPlayer.SelectedValue + "", connection))
        {
           command.Parameters.Add(new SqlParameter ("",));
        }
     }
  }
  </code></pre>
  
  <p>All help is appreciated and please go easy on me :P</p>