Private Sub ComboBox6_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox6.SelectedIndexChanged
con = New SqlConnection("Data Source=DEW-D63D9D2D032\SQLEXPRESS;Initial Catalog=system1;Integrated Security=True")
con.Open()
sql = "Select Faculty_Id From Faculty where Faculty_Name='" + ComboBox6.SelectedItem.ToString() + "'"
cmd = New SqlCommand(sql, con)
rdr = cmd.ExecuteReader()
While (rdr.Read())
fid = rdr.GetInt32(0)
End While
con.Close()
MsgBox(fid)
con1 = New SqlConnection("Data Source=DEW-D63D9D2D032\SQLEXPRESS;Initial Catalog=system1;Integrated Security=True")
con1.Open()
sql1 = "Select Department_Name From Department_Master where Faculty_Id=" + fid
cmd1 = New SqlCommand(sql1, con1)
rdr1 = cmd1.ExecuteReader()
While (rdr1.Read())
ComboBox7.Items.Add(rdr1.GetString(0))
End While
con1.Close()
its gives an error
here fid is fk in department table