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

Conversion from string "Select Department_Name From Depa" to type 'Double' is not valid.

on insert and select for int we need to used syntax as & fid &

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.