通过从其他组合框中选择值来填充组合框

时间:2014-11-06 14:04:36

标签: mysql vb.net datagrid

我得到以下错误, 我的代码是:

Private Sub Cmb_name_final_SelectedIndexChanged(sender As Object, e As EventArgs)  
     Handles Cmb_name_final.SelectedIndexChanged

    Cbofill(dsetreg, "select* from Student_info where ID=" & 
          Me.Cmb_name_final.SelectedValue & "", Me.Cmb_reg_final, 
         "Student_registration", "ID")

End Sub

给出错误:

Operator '&' is not defined for string "select* from Student_info where " and type 'DataRowView'.

1 个答案:

答案 0 :(得分:0)

您应该显示CboFill()方法的代码,以提供更完整的问题。

但是,您的问题只是您尝试将字符串("select *...")与DataRowView(Me.Cmb_name_final.SelectedValue)连接起来。

更新您的代码以访问包含您要查询的值的DataRowView列,您应该超越此错误。类似于DirectCast(Me.Cmb_name_final.SelectedValue, DataRowView)("ID")

整个事情可能看起来像这样:

Private Sub Cmb_name_final_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cmb_name_final.SelectedIndexChanged 
    Cbofill(dsetreg, "select* from Student_info where ID="& DirectCast(Me.Cmb_name_final.SelectedValue, DataRowView)("ID") &"", Me.Cmb_reg_final, "Student_registration", "ID") 
End Sub