I have basically a combobox and and a text box. What should i do is the combobox consist of subject code whereas the textbox consist of subject name which is stored in database. Can i know is there any ways that when an item from combobox is chosen, it is automatically display subject name based on subject code chosen which will be from the database. belwo is my code but not working
private void FormAttendanceFaculty_Load(object sender, EventArgs e)
con.Open();
OleDbDataAdapter oda1 = new OleDbDataAdapter("select code from subject where code like '%'", con);
DataTable dt1 = new DataTable();
oda1.Fill(dt1);
comboBoxCode.DataSource = dt1;
comboBoxCode.DisplayMember = "code";
comboBoxCode.SelectedIndex = -1;
string myquery = "SELECT name FROM subject where name = '" +comboBoxName.Text + "'";
using (var command = new OleDbCommand(myquery, connection))
{
MyTextBox.Text = command.ExecuteScalar().ToString();
}
}