添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Hello
Im having problems in getting data from the related tables using selectedvalue in combobox. this is my code:
vb.net Code:
  1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  2.      
  3.   For Each c As Control In Me.Controls
  4.             If TypeOf c Is GroupBox Then
  5.                 Me.Controls.Remove(c)
  6.             End If
  7.         Next
  8.  
  9.       Dim adptr As New MySqlCommand("SELECT * FROM positions WHERE election_id = ?election_id", conn)
  10.         adptr.Parameters.Add("?election_id", MySqlDbType.Int32)
  11.         adptr.Parameters("?election_id").Value = ComboBox1.SelectedValue
  12.         Dim positions As New DataTable
  13.         Dim positionAdapter As MySqlDataAdapter = New MySqlDataAdapter(adptr)
  14.         positionAdapter.Fill(positions)
and error appeared to say:
Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.
Thanks in advance for anyone who could help me. You haven't set the ValueMember of your ComboBox. If you don't then the item itself is returned by SelectedValue. If you've bound a DataTable then each item is a DataRowView, not an individual field value. If you expect SelectedValue to return a value from a specific column of your table then you need to assign the name of that column to the ValueMember property of the ComboBox.
Thanks can u pls give me an example how to set the valuemember for my combobox. im new into this type of application.
Thanks in advance. Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.