Results 1 to 8 of 8

Thread: Listview only gives ID in return

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Listview only gives ID in return

    Dear all

    I created a listview and the only Item I get into this window is the ID of my db.
    if I check if the while is correctly implemented I can see that All the info of the given ID is presented correctly, can anyone help me on how to solve this

    Code:
    Public Class Form1
        Sub FillComboOs()
            strsql = "select * from Os"
            Dim acscmd As New OleDb.OleDbCommand
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acsdr = acscmd.ExecuteReader
            While (acsdr.Read())
                CbxOs.Items.Add(acsdr("Windows"))
            End While
            acscmd.Dispose()
            acsdr.Close()
        End Sub
        Sub FillComboOffice()
            strsql = "select * from Office"
            Dim acscmd As New OleDb.OleDbCommand
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acsdr = acscmd.ExecuteReader
            While (acsdr.Read())
                CbxOffice.Items.Add(acsdr("OfficeVersion"))
            End While
            acscmd.Dispose()
            acsdr.Close()
        End Sub
        Sub FillComboInstall()
            strsql = "select * from installtype"
            Dim acscmd As New OleDb.OleDbCommand
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acsdr = acscmd.ExecuteReader
            While (acsdr.Read())
                CbxInstal.Items.Add(acsdr("installed"))
            End While
            acscmd.Dispose()
            acsdr.Close()
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            modCon.connect()
            Me.FillComboOs()
            Me.FillComboOffice()
            Me.FillComboInstall()
            Me.filllsitview()
        End Sub
    
        Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
            'sqlstatements
            strsql = "insert into TelelinkTable (Datum, ContactPerson, ContactPhone, IsaAbo, IsaAdminUser, Os, Os64, Office, Of64, InstallType, Remarks) values ('" _
                & DateTimePicker1.Text & "','" _
                & txtContact.Text & "','" _
                & txtPhone.Text & "','" _
                & txtIsaAbo.Text & "','" _
                & TxtIsaAdmin.Text & "','" _
                & CbxOs.Text & "','" _
                & RdbOs64.Text & "','" _
                & CbxOffice.Text & "','" _
                & RdbOf64.Text & "','" _
                & CbxInstal.Text & "','" _
                & txtRemark.Text & "')"
    
            Dim acscmd As New OleDb.OleDbCommand ' the oledbcommand
            acscmd.CommandText = strsql 'sets the sql string
            acscmd.Connection = acsconn 'sets the connection to use the oledbcommand
            acscmd.ExecuteNonQuery() ' execute oledb commands non query only
            acscmd.Dispose()
            MsgBox("Saved")
            'Me.filllsitview()
        End Sub
    
        Sub filllsitview()
            'sql statements
            strsql = "select * from TelelinkTable"
            Dim acscmd As New OleDb.OleDbCommand
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acsda.SelectCommand = acscmd
            acsdr = acscmd.ExecuteReader()
    
            'clear the listview
            ListView1.Items.Clear()
            'display the result of the query into the listview
            While (acsdr.Read())
                With ListView1.Items.Add(acsdr("Id"))
                    .subitems.add(acsdr("Datum"))
                    .subitems.add(acsdr("ContactPerson"))
                    .subitems.add(acsdr("ContactPhone"))
                    .subitems.add(acsdr("IsaAbo"))
                    .subitems.add(acsdr("IsaAdminUser"))
                    .subitems.add(acsdr("Os"))
                    .subitems.add(acsdr("Os64"))
                    .subitems.add(acsdr("Office"))
                    .subitems.add(acsdr("Of64"))
                    .subitems.add(acsdr("InstallType"))
                    .subitems.add(acsdr("Remarks"))
                End With
            End While
            acscmd.Dispose()
            acsdr.Close()
    
    
        End Sub
        Private Sub ListView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
            'displays the details from the listview to the textbox
            With ListView1.SelectedItems(0)
                txtid.Text = .SubItems(0).Text
                DateTimePicker1.Text = .SubItems(1).Text
                txtContact.Text = .SubItems(2).Text
                txtPhone.Text = .SubItems(3).Text
                txtIsaAbo.Text = .SubItems(4).Text
                TxtIsaAdmin.Text = .SubItems(5).Text
                CbxOs.Text = .SubItems(7).Text
                RdbOs64.Text = .SubItems(8).Text
                CbxOffice.Text = .SubItems(9).Text
                RdbOf64.Text = .SubItems(10).Text
                CbxInstal.Text = .SubItems(11).Text
                txtRemark.Text = .SubItems(12).Text
    
            End With
        End Sub
        
    
    
        Private Sub txtIsaAbo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIsaAbo.TextChanged
            searchrecord(txtIsaAbo.Text)
        End Sub
    
        Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    
        End Sub
    
        Sub searchrecord(ByVal searchword As String)
            'sql statements
            strsql = "select * from TelelinkTable where IsaAbo like '" & searchword & "%'"
            Dim acscmd As New OleDb.OleDbCommand
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acsda.SelectCommand = acscmd
            acsdr = acscmd.ExecuteReader
            'clear the listview
            ListView1.Items.Clear()
            While (acsdr.Read())
                With ListView1.Items.Add(acsdr("Id"))
                    .subitems.add(acsdr("Datum"))
                    .subitems.add(acsdr("ContactPerson"))
                    .subitems.add(acsdr("ContactPhone"))
                    .subitems.add(acsdr("IsaAbo"))
                    .subitems.add(acsdr("IsaAdminUser"))
                    .subitems.add(acsdr("Os"))
                    .subitems.add(acsdr("Os64"))
                    .subitems.add(acsdr("Office"))
                    .subitems.add(acsdr("Of64"))
                    .subitems.add(acsdr("InstallType"))
                    .subitems.add(acsdr("Remarks"))
                End With
            End While
            acscmd.Dispose()
            acsdr.Close()
    
        End Sub
    
        Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Me.Close()
    
        End Sub
    End Class

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Re: Listview only gives ID in return

    Why not use a datagridview? All you need to then is fill a datatable and assign the datatable to the datagridview datasource property.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: Listview only gives ID in return

    can you use the datagrid view also to search for a specific word or user?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Listview only gives ID in return

    vb.net Code:
    1. With ListView1.Items.Add(acsdr("Id")) ' this is nonsensical!
    2.                 .subitems.add(acsdr("Datum")) ' what are the subitems of Add()?
    3.                 .subitems.add(acsdr("ContactPerson"))
    4.                 .subitems.add(acsdr("ContactPhone"))
    5.                 .subitems.add(acsdr("IsaAbo"))
    6.                 .subitems.add(acsdr("IsaAdminUser"))
    7.                 .subitems.add(acsdr("Os"))
    8.                 .subitems.add(acsdr("Os64"))
    9.                 .subitems.add(acsdr("Office"))
    10.                 .subitems.add(acsdr("Of64"))
    11.                 .subitems.add(acsdr("InstallType"))
    12.                 .subitems.add(acsdr("Remarks"))
    13.             End With

    With takes an object. It can't take a function. Just simple logic. Compare "with this apple I will charm my teacher" and "with this eat apple I will charm my teacher".
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: Listview only gives ID in return

    dunfiddlin
    thanks for your reaction
    I was just following this tutorial http://www.youtube.com/watch?v=xrPZa...F829AF&index=5

    and there it works

    can you explain what I need to do to get the grid view just like this

    thanks again for your feedback

    Paul

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Listview only gives ID in return

    vb.net Code:
    1. While (acsdr.Read())
    2.             Dim lvItem As New ListViewItem(acsdr("Id"))
    3.             With lvItem
    4.                 .SubItems.Add(acsdr("Datum"))
    5.                 ' etc.
    6.             End With
    7.             ListView1.Items.Add(lvItem)
    8.         End While
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: Listview only gives ID in return

    dunfiddlin,
    I get an error on your solution

    this is the error
    Error 1 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(group As System.Windows.Forms.ListViewGroup)': Argument matching parameter 'group' narrows from 'Object' to 'System.Windows.Forms.ListViewGroup'.
    'Public Sub New(items() As String)': Argument matching parameter 'items' narrows from 'Object' to '1-dimensional array of String'.
    'Public Sub New(text As String)': Argument matching parameter 'text' narrows from 'Object' to 'String'. d:\my documents\visual studio 2010\Projects\telelink-accdb\telelink-accdb\Form1.vb 84 17 telelink-accdb

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Listview only gives ID in return

    Sorry about that. I'm afraid I never use DataReader so I just assumed that acsdr("Id") returned a string value (it would have to to work with the add function). Obviously not. To be honest this is one of the reasons I doubted that this ever worked. Frankly I would tend to avoid tutorials that start with a disclaimer like "I'm not very good at coding" because with the best will in the world this whole thing is pretty much proof of it! It's a mess from top to bottom. I'm sure you've put a lot of effort into this but you'll learn nothing from it but how not to do it.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width