0

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();
}

}
3
Contributors
2
Replies
14
Views
1 Year
Discussion Span
Last Post by Reverend Jim
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.