Dim sql3 As String
Dim dt4 As New DataTable
sql3 = "SELECT class.class_name, teacher.first_name, course.cours_name, class.class_char" _
& " FROM class INNER JOIN" _
& " lecture ON class.class_num = lecture.class_num INNER JOIN" _
& " course ON lecture.cours_num = course.cours_num INNER JOIN" _
& " teacher ON lecture.teacher_id = teacher.teacher_id" _
& " WHERE (class.class_name = '" & cbox_class.Text & "') AND(teacher.first_name = '" & cbox_teacher_name.Text & "')"
Dim da5 As New SqlDataAdapter()
da5 = New SqlDataAdapter(sql3, conn)
da5.Fill(dt4)
cbox_cours.DropDownStyle = ComboBoxStyle.DropDownList
cbox_cours.DataSource = dt4
cbox_cours.DisplayMember = "cours_name"
cbox_cours.ValueMember = "cours_num"
答案 0 :(得分:1)
您的查询未返回cours_num
更改
"SELECT class.class_name, teacher.first_name, course.cours_name, class.class_char" _
到
"SELECT class.class_name, teacher.first_name, course.cours_name, course.cours_num, class.class_char" _
答案 1 :(得分:1)
您的查询似乎没有返回cours_num
字段。您必须在查询中包含缺少的字段,或更正ValueMember
值,以便使用正确的字段。
作为旁注,您应该知道您当前的代码是Sql injection attacks的广泛开放。您应该使用参数化查询,而不是连接UI控件中的值。