how can i get data in textboxes from database if my combobox selected values are from table1 and the values i want to get in textboxes are from table2 ?
i am getting name of just 1 subject in all textboxes i want all subject to show in textboxes after selecting class from combox
What I have tried:
private void Result_Load(object sender, EventArgs e)
{
string query = "SELECT class_id , class_name FROM class";
fillcombo(comboBox3, query, "class_name", "class_id");
}
public void fillcombo(ComboBox combo, string query, string displayMember, string valueMember)
{
command = new SqlCommand(query, con);
adapter = new SqlDataAdapter(command);
table = new DataTable();
adapter.Fill(table);
combo.DataSource = table;
combo.DisplayMember = displayMember;
combo.ValueMember = valueMember;
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
int val;
Int32.TryParse(comboBox3.SelectedValue.ToString(), out val);
string query = "SELECT dbo.Subject.sub_name, dbo.Class.class_name FROM dbo.Class full JOIN dbo.Subject ON dbo.Class.class_id = dbo.Subject.class_id where Class.class_id="+val;
SqlCommand command = new SqlCommand(query, con);
using (var reader = command.ExecuteReader())
{
if (reader.Read())
{
textBox1.Text = reader["sub_name"].ToString();
textBox2.Text = reader["sub_name"].ToString();
textBox3.Text = reader["sub_name"].ToString();
textBox4.Text = reader["sub_name"].ToString();
textBox5.Text = reader["sub_name"].ToString();
textBox7.Text = reader["sub_name"].ToString();
textBox8.Text = reader["sub_name"].ToString();
textBox9.Text = reader["sub_name"].ToString();
textBox10.Text = reader["sub_name"].ToString();
textBox11.Text = reader["sub_name"].ToString();
}
reader.Close();
}
con.Close();
}