Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid ?
-
"cbComLevel" is a combo box(dropdown list) and "ComLevelDetail" is a datatable contains data from database. i using this method to bind data to combo box. '--------------------------- With cbComLevel .DataSource = ComLevelDetail .DisplayMember = "ComLevel" .ValueMember = "ID" End With Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString) label1.text = ComLevelID '--------------------------- so this code work fine while i compile the application. but while i add new code below in order to get the selected value from this combo box while the combo box selected index changed: '--------------------------- Private Sub cbComLevel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbComLevel.SelectedIndexChanged Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString) label1.text = ComLevelID End Sub '--------------------------- the error message come out : Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid. I still no idea how to solve it, Who know what happen?
Best regards, Chee ken
-
"cbComLevel" is a combo box(dropdown list) and "ComLevelDetail" is a datatable contains data from database. i using this method to bind data to combo box. '--------------------------- With cbComLevel .DataSource = ComLevelDetail .DisplayMember = "ComLevel" .ValueMember = "ID" End With Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString) label1.text = ComLevelID '--------------------------- so this code work fine while i compile the application. but while i add new code below in order to get the selected value from this combo box while the combo box selected index changed: '--------------------------- Private Sub cbComLevel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbComLevel.SelectedIndexChanged Dim ComLevelID As Integer = CInt(cbComLevel.SelectedValue.ToString) label1.text = ComLevelID End Sub '--------------------------- the error message come out : Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid. I still no idea how to solve it, Who know what happen?
Best regards, Chee ken
It looks like the object you are returning is a DataRowView Object. Try Dim ComLevelID As Object = cbComLevel.SelectedValue Set your breakpoint on the next line and look at the value of ComLevelId in Watch Window to see exactly what you are returning and modify your code to fit.
-
It looks like the object you are returning is a DataRowView Object. Try Dim ComLevelID As Object = cbComLevel.SelectedValue Set your breakpoint on the next line and look at the value of ComLevelId in Watch Window to see exactly what you are returning and modify your code to fit.
Thanks for reply. i put a breakpoint on that code line, then the watch window return value "Nothing" for comlevelID, and i press F10,while it jump to next code line, the watch window show that the comlevelID is "{System.Data.DataRowView}". Is it cannot get the selectedvalue?
Best regards, Chee ken
-
Thanks for reply. i put a breakpoint on that code line, then the watch window return value "Nothing" for comlevelID, and i press F10,while it jump to next code line, the watch window show that the comlevelID is "{System.Data.DataRowView}". Is it cannot get the selectedvalue?
Best regards, Chee ken
What is happening is you are returning a object not a integer, so what happens is when you use the toString method you get the text of the type, in this case the System.Data.DataRowView. If you made the changes I suggested you should be looking at the object and not the Text. You should be able to expand the object to see what property or method you need, most likely : cbComLevel.SelectedValue.Value or cbComLevel.SelectedValue.Row