DataRowView casting to a String

epower

New member
Joined
Mar 22, 2005
Messages
3
Programming Experience
3-5
Im kind of new to this so any help would be greatly appreciated.
My first project in VB is to develop a form in which I am inserting data into a database. On this form I have a combo box that is populated from a single data set through the use of OdbcDataAdapter into a DataSet.
On the form load I populate this data set which is bound to my combo box. I would like to use this selected item in a later event to be used as a value that will be inserted into the database.
Currently I am not able to retrieve the value of the item selected in the combo box. At this point of development if I can just get the value to resolve I will be happy.
Here is my code for the event.

PrivateSub LeadTech_SelectedIndexChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
leadTechCombo.SelectedIndexChanged
Dim Techno = leadTechCombo.SelectedItem
MessageBox.Show(Techno)
EndSub

My Current Debug Message is the following:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'DataRowView' to type 'String' is not valid.


If I change leadTechCombo.SelectedItem to .SelectedIndex it properly
shows what index is being selected but I need the value. This is not an issue when i have my collection hard coded but I need the values appearing to be dynamic based on the results of my SQL query.
If anyone can help I would greatly appreciate it.
Thanks,
Emilio
 

epower

New member
Joined
Mar 22, 2005
Messages
3
Programming Experience
3-5
I have tried this and still no go

Private Sub LeadTech_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leadTechCombo.SelectedIndexChanged

Dim technotable

technotable = TechnicianSet1.Tables(0)

Dim Techno As String = Convert.ToString(technotable.Rows(leadTechCombo.SelectedIndex))

MessageBox.Show(Techno)

End Sub

And the message I get is
WindowsApplication1.TechnicianSet+UsersRow
 

epower

New member
Joined
Mar 22, 2005
Messages
3
Programming Experience
3-5
I got it to work!!!

Private Sub LeadTech_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leadTechCombo.SelectedIndexChanged

Dim technotable

technotable = TechnicianSet1.Tables(0)

Dim Techno As String = Convert.ToString(technotable.Rows(leadTechCombo.SelectedIndex)(0))

MessageBox.Show(Techno)

End Sub

 
Top Bottom