hi...i have an application which stores records in a text file. the application loads the records in array of objects when the page is loaded. then, we can add, search, delete the records in array and save the array back to the file. code for inserting new record and then saving it works fine. am havin problem wid searching. search is based on ID.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim d As New Developer
Dim reader As System.IO.StreamReader
Dim strInput As String
If File.Exists(Request.MapPath("developer.txt")) Then
reader = System.IO.File.OpenText(MapPath("developer.txt"))
While reader.Peek <> -1
strInput = reader.ReadLine()
Dim splitout As String()
splitout = Split(strInput, " ")
d.DeveloperID = splitout(0)
d.Name = splitout(1)
d.Salary = splitout(2)
DeveloperBook.Add(d)
End While
Session("Developer") = DeveloperBook
Else
MsgBox("File not found")
End If
End If
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim d As New Developer
Dim DeveloperBook As ArrayList = getSession()
Dim i As Integer
For i = 0 To DeveloperBook.Count - 1
If CType(DeveloperBook(i), Developer).DeveloperID = txtID.Text Then
txtName.Text = CType(DeveloperBook(i), Developer).Name
txtSalary.Text = CType(DeveloperBook(i), Developer).Salary
Exit For
End If
Next
Session("Developer") = DeveloperBook
End Sub
Private Function getSession() As ArrayList
Return CType(Session("Developer"), ArrayList)
End Function
Comment