title: VB 2010 search CSV records - match search term to return records
body: <p>I have a csv file with 8 fields and multiple records. 
  I would like to search the ID field (the first field) by entering a search term in a text box, find the matching record/s and display the full record/s on the VB form in a multi-line text box. I would also like to search by date to find all dates ending in a given year e.g. 2009, with all matching full record/s being returned. 
  I’ve got so far with the code below, and can return all data in the file but haven’t been able to achieve the search – I tried the commented-out IF statement but couldn’t get it working. 
  Sample CSV follows the code below.
  Any help would be great. Thanks.</p>
  
  <pre><code>Imports System.IO
  
  Public Class Form1
  
  Private Sub btnSearchName_Click(sender As System.Object,...
  
      Dim fileIn As String
      Dim fileRows(), fileFields() As String
  
      fileIn = "C:\SuppliersSearch_Test\suppliers.csv"
  
      Label1.Text = String.Empty
  
      If IO.File.Exists(fileIn) Then
          Dim fileStream As StreamReader = File.OpenText(fileIn)
          fileRows = fileStream.ReadToEnd().Split(Environment.NewLine)
          For i As Integer = 0 To fileRows.Length - 1
              fileFields = fileRows(i).Split(",")
              If fileFields.Length &gt;= 8 Then
  
                  ' ?? loop to see if field0 contains the inputted surname, return the record
                  'then check the next record until ALL records checked and matching ones returned
  
          ‘ if fileFields(0) = txtSearch.text then
  
                  txtResults.Text += fileFields(0) &amp; ", " &amp; fileFields(1) &amp; ", " &amp; fileFields(3) &amp; ", " &amp; fileFields(4) &amp; ", " &amp; fileFields(5) &amp; ", " &amp; fileFields(6) &amp; ", " &amp; fileFields(7)
  
  
              End If
          Next
      Else
          txtResults.Text = fileIn &amp; " not found."
      End If
  End Sub
  
  
  End Class
  </code></pre>
  
  <p>Sample CSV data. To aid clarity, each record ends with ".com":</p>
  
  <blockquote>
    <p>Supp1,1 Blue,1  Socks,01/01/2008,1 SocksSupplier,1 Socks supp
    address,1 Socks phone,1 Socks@socks.com Supp2,2 Pink,2
    Shoes,01/05/2009,2 ShoesSupplier,2 Shoes supp address,2 Shoes supp
    phone,2 Shoes@shoes.com Supp3,3 Red,3 Bag,04/03/2009,3 BagSupplier,3
    Bag supplier adress,3 Bag supp phone,3 bags@bags.com Supp4,4 Gren,4
    Tie,05/03/2007,4 TieSupplier,4 Tie Supplier address,4 Tie supp phone,4
    tie_supp@ties.com Supp5,5 Grey,5 Suit,13/05/2009,5 SuitSupplier,5 Suit
    Supplier address,5 Suit supp phone,5 suitsupp@suits.com Supp6,6
    Black,6 Skirt,14/05/2008,6 SkirtSupplier,6 Skirt Supplier address,6
    Skirt supp phone,6 skirtsupp@skirts.com</p>
  </blockquote>