2014-05-01 58 views
-2

這是一個鱈魚,當它做它爲combobox它來了我一個thes消息 我不敢喋喋不休「canot綁定新值member.parameter名稱:值「Winforms combobox canot綁定新值member.parameter name:value

 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" 

回答

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

您的查詢似乎沒有返回cours_num字段。您必須在查詢中包含缺少的字段,或更正ValueMember值,以便使用正確的字段。

作爲一個附註,你應該知道你的當前代碼是全開的Sql injection attacks。您應該使用參數化查詢,而不是連接UI控件的值。