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:
LstResults.Items.Clear() If con.State <> ConnectionState.Open Then Try con.Close() Catch ex As Exception End Try con.Open() End If Dim comm As New SqlCommand("select * from maxcom WHERE LastName like '%" & TxtLastName.Text & "%' OR FirstName like '%" & TxtLastName.Text & "%'", con) ' OR Position like '%" & TxtLastName.Text & "%'" ' OR FirstName like '%" & TxtLastName.Text & "%' OR Position like '%" & TxtLastName.Text & "%' OR " Try Dim reader As SqlDataReader = comm.ExecuteReader() While reader.Read() LstResults.Items.Add(reader("FirstName").ToString() & " " & reader("LastName").ToString() & " " & reader("Extension").ToString() & " " & reader("DIDNumber").ToString()) LstResults.Items.Add("-----------------------------------------------------------------------------------------------------------------------------------------------------------------") End While reader.Close() Catch ex As Exception End Try If TxtLastName.Text.ToString.Contains(Chr(32)) Then Dim line As String = TxtLastName.Text.ToString Dim i As Integer Dim aryTextFile() As String aryTextFile = line.Split(Chr(32)) For i = 0 To UBound(aryTextFile) Dim comm2 As New SqlCommand("select * from maxcom WHERE LastName like '%" & aryTextFile(i).ToString & "%' OR FirstName like '%" & aryTextFile(i).ToString & "%'", con) Dim reader As SqlDataReader = comm2.ExecuteReader() While reader.Read() LstResults.Items.Add(reader("FirstName").ToString() & " " & reader("LastName").ToString() & " " & reader("Extension").ToString() & " " & reader("DIDNumber").ToString()) LstResults.Items.Add("-----------------------------------------------------------------------------------------------------------------------------------------------------------------") End While reader.Close() Next i End If con.Close() TxtLastName.Text = "" TxtLastName.Focus()





Reply With Quote
