ranadev ranadev - 1 year ago 87
Vb.net Question

Conversion to string 'System.data.dataRowView' to type integer is invalid in vb.net with 2 dropdownlist

I have a small problem in my vb.net code. The error is


conversion to string 'System.data.dataRowView' to type integer is invalid


How can I fix it? I have 2 dropdownlist, first one; when I choose an option, all the data related to that option, should appear in the second dropdownlist. Part of my code:

Dim sb As New StringBuilder
sb.Append("select date_collected, spectral_id from Spectral_information")
sb.Append("inner join Crop on crop_id = si_crop_id")
sb.Append("where si_crop_id =")
sb.Append(CInt(crop.SelectedValue.ToString()))
Dim str As String = sb.ToString()


etc..

djv djv
Answer Source

The line

sb.Append(CInt(crop.SelectedValue.ToString())) 

seems silly doesn't it? Why convert the selected value to string, then int, then back to string in StringBuilder.Append(Integer)? If you expect an Integer there, then you have an issue when there isn't. You should address that first. Changing the line to this

sb.Append(crop.SelectedValue.ToString())

should make it work. Then you need to address the logic.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download