I am currently working on a Library Inventory System. I wanted it to be able to add, issue, search and delete book records. The records are stored in a text file which looks like this:
(ID), (Name Of Book); (Author); (Price) ; (Book Donor) ; (Language)
E.g.
123 , Journey to the center of the earth ; Jules Verne ; 50 ; Jack ; English
...
This program also works with a datagridview to update to/from the text file, so far my add and issue functions are working but i am having trouble with search and delete.
To search, the user must either enter the ID of the book in a textbox or the language of the book (separate textbox) and it must show the search results in the datagridview.
This is the my attempt for the search function:
    Dim line As String
    Dim fields(7) As String
    Dim found As Boolean = False
    Dim inputStream As StreamReader
    inputStream = File.OpenText("AddBookScreen.txt")
    line = inputStream.ReadLine()
    While (line <> Nothing) And found = False
        fields = Split(line, ",")
        If Trim(fields(0)) = SBidTextbox.Text Then
            SBdatagridview.Rows.Add(Trim(fields(1)), Trim(fields(2)), Trim(fields(3)), Trim(fields(4)), Trim(fields(5)), Trim(fields(6)))
            found = True
        Else
            line = inputStream.ReadLine()
        End If
    End While
    If Not found Then
        MessageBox.Show(SBidTextbox.Text & " not found")
    End If
    inputStream.Close()
End Sub
The delete function should be able to find the specific book by id and then delete that record from the text file.
This is my attempt for the delete function:
    Dim lines() As String
    Dim outputlines As New List(Of String)
    Dim searchString As String = DBidTextbox.Text
    lines = IO.File.ReadAllLines("AddBookScreen.txt")
    For Each line As String In lines
        If line.Contains(searchString) = False Then
            outputlines.Add(line)
        End If
    Next
The search and delete methods are meant to search for a specific book in the text file by either the ID of the book or the language and display the results in the datagridview, the delete method is to search for a specific record through ID and delete that record.
Could someone please guide me through these problems, your help would be much appreciated.
 
     
    