I have been using this code, see below, to try and write data from the DataGridView to a text file. It works but it puts an extra comma after each line and thinks that there has been another line so puts an extra 4 commas on a new line. So the text file looks like this:
I'm looking for any help for a way to get rid of the extra commas or an entirely different way of doing this whole process.
If you need any extra information - please do ask.
VB.NET:
9,Here to There,1,15,
8,Hell to Heaven,16,34,
,,,,
I'm looking for any help for a way to get rid of the extra commas or an entirely different way of doing this whole process.
If you need any extra information - please do ask.
VB.NET:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim fsStream As New FileStream("routes.txt", FileMode.Create, FileAccess.Write)
Dim swWriter As New StreamWriter(fsStream)
Try
Dim temp As Integer
For temp = 0 To dg.Columns.Count - 1
Dim temp2 As Integer
For temp2 = 0 To dg.Columns.Count - 1
swWriter.Write(dg.Rows.Item(temp).Cells.Item(temp2).Value)
swWriter.Write(",")
Next
swWriter.WriteLine("")
Next
swWriter.Flush()
MsgBox("Data Saved Successfully")
swWriter.Close()
Catch ex As Exception
End Try
End Sub