hi,
Please help me with my listview. The listview did'nt show any list items.

here's my code:

Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged

        Dim strSearch As String

        strSearch = "SELECT * FROM tblMobileTracking WHERE accountNumber LIKE '" & txtSearch.Text & "%'"
        myConnection.Open()

        Dim cmdAcctNum As OleDbCommand = New OleDbCommand(strSearch, myConnection)

        Dim objDataReader As OleDbDataReader = cmdAcctNum.ExecuteReader

        If objDataReader.Read = 0 Then

        End If
        Try


            lvwSearch.Items.Clear()

            While objDataReader.Read
                Dim lv As New ListViewItem
                With lv
                    .Text = objDataReader.Item("accountNumber")
                    .SubItems.Add(objDataReader("division"))
                    .SubItems.Add(objDataReader("Assignee"))
                    .SubItems.Add(objDataReader("phoneUnitModel"))
                    .SubItems.Add(objDataReader("handPhoneNumber"))
                End With
                lvwSearch.Items.Add(lv)
            End While
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        myConnection.Close()

    End Sub

Assuming there is one record to show, the

If objDataReader.Read = 0 Then
         
End If

will read the first record returned; then

While objDataReader.Read

will try to read the second one, but only one exist so the condition is currently false and nothing filled in the listview.

I will suggest the following code

If objDataReader.HasRows() Then
    Try              
        lvwSearch.Items.Clear()
        While objDataReader.Read
            Dim lv As New ListViewItem
            With lv
               .Text = objDataReader.Item("accountNumber")                    
               .SubItems.Add(objDataReader("division"))
               .SubItems.Add(objDataReader("Assignee"))
               .SubItems.Add(objDataReader("phoneUnitModel"))
               .SubItems.Add(objDataReader("handPhoneNumber"))
            End With
            lvwSearch.Items.Add(lv)
        End While
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    myConnection.Close()
End If

Hope this helps

Thanks for that one lolafuertes,. i've modified some area,.thanks again., i have another question.how can i insert to database from variable. thanks alot

hi lola, i've already solved my question,.,. here's another one., how can i delete/edit/update the row that i've selected in the listview

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.