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. Type mismatch when loading data from db to listview

Type mismatch when loading data from db to listview

Scheduled Pinned Locked Moved Visual Basic
csharphelpasp-netdatabase
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.
  • M Offline
    M Offline
    misCafe
    wrote on last edited by
    #1

    I am using VBA (Access 2007) for my project. On the form load, listview retrieves data from the db but gets problem (Error Message : Type mismatch). Here is my code. Dim Rst As New ADODB.Recordset Dim Str As String Rst.CursorLocation = adUseClient Str = "Select * From qry_staff_info Order By sID" Rst.Open Str, Application.CodeProject.Connection, adOpenDynamic If Rst.RecordCount < 0 Then Exit Sub If Rst.RecordCount > 0 Then Do While Not Rst.EOF Dim lvwItem As ListItem Set lvwItem = Me.lvwStaff.ListItems.Add(, , Rst![insurno]) ''''''' This the line which debug and show the error message (Type mismatch) lvwItem.SubItems(1) = Rst![sname] lvwItem.SubItems(2) = Rst![bgroup] lvwItem.SubItems(3) = Rst![gender] lvwItem.SubItems(4) = Rst![dob] lvwItem.SubItems(5) = Rst![doj] lvwItem.SubItems(6) = Rst![Position] lvwItem.SubItems(7) = Rst![location] lvwItem.SubItems(8) = Rst![Address] lvwItem.SubItems(9) = Rst![Telephone] lvwItem.SubItems(10) = Rst![martialstatus] lvwItem.SubItems(11) = Rst![nod] Loop End If Thanks,

    Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

    L 1 Reply Last reply
    0
    • M misCafe

      I am using VBA (Access 2007) for my project. On the form load, listview retrieves data from the db but gets problem (Error Message : Type mismatch). Here is my code. Dim Rst As New ADODB.Recordset Dim Str As String Rst.CursorLocation = adUseClient Str = "Select * From qry_staff_info Order By sID" Rst.Open Str, Application.CodeProject.Connection, adOpenDynamic If Rst.RecordCount < 0 Then Exit Sub If Rst.RecordCount > 0 Then Do While Not Rst.EOF Dim lvwItem As ListItem Set lvwItem = Me.lvwStaff.ListItems.Add(, , Rst![insurno]) ''''''' This the line which debug and show the error message (Type mismatch) lvwItem.SubItems(1) = Rst![sname] lvwItem.SubItems(2) = Rst![bgroup] lvwItem.SubItems(3) = Rst![gender] lvwItem.SubItems(4) = Rst![dob] lvwItem.SubItems(5) = Rst![doj] lvwItem.SubItems(6) = Rst![Position] lvwItem.SubItems(7) = Rst![location] lvwItem.SubItems(8) = Rst![Address] lvwItem.SubItems(9) = Rst![Telephone] lvwItem.SubItems(10) = Rst![martialstatus] lvwItem.SubItems(11) = Rst![nod] Loop End If Thanks,

      Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      misCafe wrote:

      (Error Message : Type mismatch)

      Could that be caused by insurno being a number? Try converting it explicitly;

      Set lvwItem = Me.lvwStaff.ListItems.Add(, , CStr(Rst![insurno]))

      I are Troll :suss:

      M 1 Reply Last reply
      0
      • L Lost User

        misCafe wrote:

        (Error Message : Type mismatch)

        Could that be caused by insurno being a number? Try converting it explicitly;

        Set lvwItem = Me.lvwStaff.ListItems.Add(, , CStr(Rst![insurno]))

        I are Troll :suss:

        M Offline
        M Offline
        misCafe
        wrote on last edited by
        #3

        Thanks so much for your help. The problem is fixed. :) Anyways, I want to click on the ListView Item and load its values from each colums to the TextBox, ComboBox. It is the better way to update the record.

        Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

        L 1 Reply Last reply
        0
        • M misCafe

          Thanks so much for your help. The problem is fixed. :) Anyways, I want to click on the ListView Item and load its values from each colums to the TextBox, ComboBox. It is the better way to update the record.

          Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome :)

          I are Troll :suss:

          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