|
-
Dec 4th, 2002, 06:34 AM
#1
Thread Starter
Junior Member
Casting problem
I have a combobox that I populate with values from the database. And I have written a code in the SelectedIndexChanged property of the combobox to display the selected item in a label.
VB Code:
Private Sub cbxNationality_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cbxNationality.SelectedIndexChanged
Try
lblName.Text = cbxNationality.SelectedValue
'lblName.Text = CType(cbxNationality.SelectedValue, String)
Catch exp As Exception
MessageBox.Show(Err.Number & ": " & exp.Message, Me.Text)
End Try
End Sub
However, I get this error: 13: Cast from type 'DataRowView' to type 'String' is not valid.
The commented line too does not work.
Any help will be appreciated.
-
Dec 4th, 2002, 07:40 AM
#2
Registered User
try
lblName.Text = cbxNationality.SelectedValue.ToString
I think the problem has to do with the datasource being a datarowview, because I don't get the error with a table or dataview as datasource for the combobox....
-
Dec 4th, 2002, 01:24 PM
#3
The data may look like a string, but it isn't, it's a DataRowView. Without a means to convert a DataRowView into a string, the language doesn't know what to do with the line you wrote. This is just a type safety issue which you'll have to live with. In VB6, it was possible to convert just about anything into a string in some manner, but in .NET it isn't quite as simple.
-
Dec 7th, 2002, 05:39 AM
#4
Thread Starter
Junior Member
So what do you suggest I should do? Just a hint go get me in the right direction...
-
Dec 7th, 2002, 06:20 AM
#5
Registered User
Try using the Row property of the DataRowView object to get the information from the dataset then.
Datarowview.Row.Item("ColumnInDataBase")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|