Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid ?

Conversion from string "System.Data.DataRowView" to type 'Integer' is not valid ?

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheeken2u
    wrote on last edited by
    #1

    "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

    M 1 Reply Last reply
    0
    • C cheeken2u

      "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

      M Offline
      M Offline
      M Hall
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • M M Hall

        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.

        C Offline
        C Offline
        cheeken2u
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • C cheeken2u

          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

          M Offline
          M Offline
          M Hall
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups