I use the following code into the CSV file info display give the data grid:
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sr As New IO.StreamReader("C:\Data.csv")
Dim dt As New DataTable
Dim newline() As String = sr.ReadLine.Split(","c)
dt.Columns.AddRange({New DataColumn(newline(0)),
New DataColumn(newline(1)),
New DataColumn(newline(2))})
While (Not sr.EndOfStream)
newline = sr.ReadLine.Split(","c)
Dim newrow As DataRow = dt.NewRow
newrow.ItemArray = {newline(0), newline(1), newline(2)}
dt.Rows.Add(newrow)
End While
dgView.DataSource = dt
End Sub
I'm gonna change it using the code below, but the message was displayed:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim iRow As Integer = GridView1.GetSelectedRows(0)
Dim lines() As String = IO.File.ReadAllLines("C:\Data.csv")
lines(iRow) = lines(iRow).Replace("Value", "OK")
IO.File.WriteAllLines("C:\Data.csv", lines)
End Sub
The process cannot access the file 'C:\Data.csv' because it is being used by another process.
And I can not save the changes.
How do I search the CSV files to a specified field and I edit it?