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:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
For Each c As Control In Me.Controls
If TypeOf c Is GroupBox Then
Me.Controls.Remove(c)
End If
Next
Dim adptr As New MySqlCommand("SELECT * FROM positions WHERE election_id = ?election_id", conn)
adptr.Parameters.Add("?election_id", MySqlDbType.Int32)
adptr.Parameters("?election_id").Value = ComboBox1.SelectedValue
Dim positions As New DataTable
Dim positionAdapter As MySqlDataAdapter = New MySqlDataAdapter(adptr)
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.