1 Replies - 616 Views - Last Post: 12 August 2016 - 01:14 PM Rate Topic: -----

#1 vusim   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-September 11

How do I update, delete from a text file

Posted 12 August 2016 - 01:12 PM

Attached ImageAttached ImageAttached Image

Here is what I trying do with this code:
  • Enter event data on text field from a form and save it to a text file
  • When I click exit the management form loads and extracts data from the text file and then display it on the data grid view

So far everything is working as listed above, However this is what I now want to do:
  • When I select a record from the gridview, it should display on the text field of the form and allow me to change some data on the record and then update the change on the text file and display it on the gridview.
  • Select a record from gridview and delete it by clicking the delete button

Imports System.IO
Public Class AddEMForm
    Private Sub CreateCSVfile(ByVal_strCustomerCSVPath As String, ByVal EName As String, ByVal Edate As Date, ByVal ELoc As String, ByVal EDis As String, ByVal EFee As String)
            Dim stLine As String = ""
            Dim objWriter As StreamWriter = File.AppendText("..\..\EventData.txt")
            If File.Exists("..\..\EventData.txt") Then
                objWriter.Write(EName & ",")
                objWriter.Write(Edate & ",")
                objWriter.Write(ELoc & ",")
                objWriter.Write(EDis & ",")
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles LocTbx.TextChanged

    End Sub

    Private Sub AddEMForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Addbtn.Click
        CreateCSVfile(Application.StartupPath & "\" & "Events.csv", NameTbx.Text.ToString(), DatePk.Text.ToString(), LocTbx.Text.ToString(), DisTbx.Text.ToString(), FeeTbx.Text.ToString())
    End Sub
    Private Sub ClearTextbox()
        NameTbx.Text = ""
        DatePk.Text = ""
        LocTbx.Text = ""
        DisTbx.Text = ""
        NameTbx.Text = ""
        FeeTbx.Text = ""

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Exitbtn.Click
        ReadFile(Application.StartupPath & "\" & "Event.csv")
    End Sub
    Private Sub ReadFile(ByVal EventCSVPath As String)

        Const Delim As String = ","

        Dim stLine As String = ""

        Dim objReader As New StreamReader("..\..\EventData.txt")

        If File.Exists("..\..\EventData.txt") Then

            Using objReader

                While (objReader.EndOfStream) = False


                End While

            End Using


        End If


    End Sub

    Private Sub DisTbx_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DisTbx.SelectedIndexChanged

    End Sub

    Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click

    End Sub
End Class

Is This A Good Question/Topic? 0
  • +

Replies To: How do I update, delete from a text file

#2 modi123_1   User is offline

  • Suitor #2
  • member icon

Reputation: 14168
  • View blog
  • Posts: 56,760
  • Joined: 12-June 08

Re: How do I update, delete from a text file

Posted 12 August 2016 - 01:14 PM

You don't manipulate a dumb text file like some sort of indexed database. You would read all your data in, and when you are done over write it back out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1