Using the following code to add results from sql to a listview. Is there anyway that I can make a comparison from the reader against all currently existing item strings? Thanks in advance.


vb.net Code:
  1. LstResults.Items.Clear()
  2.         If con.State <> ConnectionState.Open Then
  3.             Try
  4.                 con.Close()
  5.             Catch ex As Exception
  6.  
  7.             End Try
  8.             con.Open()
  9.         End If
  10.         Dim comm As New SqlCommand("select * from maxcom WHERE LastName like '%" & TxtLastName.Text & "%' OR FirstName like '%" & TxtLastName.Text & "%'", con)
  11.         ' OR Position like '%" & TxtLastName.Text & "%'"
  12.         ' OR FirstName like '%" & TxtLastName.Text & "%' OR Position like '%" & TxtLastName.Text & "%' OR "
  13.         Try
  14.             Dim reader As SqlDataReader = comm.ExecuteReader()
  15.             While reader.Read()
  16.                 LstResults.Items.Add(reader("FirstName").ToString() & " " & reader("LastName").ToString() & "  " & reader("Extension").ToString() & "  " & reader("DIDNumber").ToString())
  17.                 LstResults.Items.Add("-----------------------------------------------------------------------------------------------------------------------------------------------------------------")
  18.             End While
  19.             reader.Close()
  20.         Catch ex As Exception
  21.  
  22.         End Try
  23.         If TxtLastName.Text.ToString.Contains(Chr(32)) Then
  24.             Dim line As String = TxtLastName.Text.ToString
  25.             Dim i As Integer
  26.             Dim aryTextFile() As String
  27.  
  28.             aryTextFile = line.Split(Chr(32))
  29.  
  30.             For i = 0 To UBound(aryTextFile)
  31.                 Dim comm2 As New SqlCommand("select * from maxcom WHERE LastName like '%" & aryTextFile(i).ToString & "%' OR FirstName like '%" & aryTextFile(i).ToString & "%'", con)
  32.                 Dim reader As SqlDataReader = comm2.ExecuteReader()
  33.                 While reader.Read()
  34.                     LstResults.Items.Add(reader("FirstName").ToString() & " " & reader("LastName").ToString() & "  " & reader("Extension").ToString() & "  " & reader("DIDNumber").ToString())
  35.                     LstResults.Items.Add("-----------------------------------------------------------------------------------------------------------------------------------------------------------------")
  36.                 End While
  37.                 reader.Close()
  38.  
  39.             Next i
  40.         End If
  41.         con.Close()
  42.         TxtLastName.Text = ""
  43.         TxtLastName.Focus()