Put some code into the
SelectedIndexChanged
event of cmbNameS to query for the appropriate data based on the
cmbNameS.SelectedItem
, then just bind the results to cmbVersion in the same way that you have done it for cmbNameS.
To display the selected version in the text box you will need code in the
SelectedIndexChanged
event of cmbVersion that just assigns the SelectedItem.ToString()
[EDIT - further information in response to OP Comment - "unable to get desired result in textbox"]
This is the code you are using to populate the text box
private void cmbVersion_SelectedIndexChanged(object sender, EventArgs e)
{
string query = "Select SKeys from dbo.Keys where SoftwareName='" + cmbVersion.SelectedValue + "'";
SqlCommand cmd = new SqlCommand(query, connect);
SqlDataReader data = cmd.ExecuteReader();
if (data.Read())
{
txtKeys.Text = data.GetSqlValue(0).ToString();
}
}
If you were to debug this you would find that your query string is incorrect or, as when I debug this, no error is displayed but processing aborts on the line
string query = "Select SKeys from dbo.Keys where SoftwareName='" + cmbVersion.SelectedValue + "'";
Change the line to
string query = "Select SKeys from dbo.Keys where SoftwareName='" + cmbVersion.SelectedItem.ToString() + "'";
and you should find that it works. (I did say SelectedItem in my original solution!)
I recommend that you do some research on simple debugging techniques - it took me seconds to find the problem once I had the code in the IDE. This CodeProject article
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^] should get you going