H
Harry Strybos
I am confused about which is the better (or safer ) way to write files in
VB.Net.
Using sw As StreamWriter = New StreamWriter(fName)
For Each row As DataRow In ds.Tables(0).Rows
For i As Integer = 0 To (ds.Tables(0).Columns.Count - 1)
col = row(i).ToString.Replace(","c, " "c) 'make sure no extra
commas
If (i < (ds.Tables(0).Columns.Count - 1)) Then
sw.Write(col & ",")
Else
sw.Write(col)
End If
Next
sw.WriteLine()
Next
sw.Close()
End Using
seems very simple, but I am told this method leaves a file open if an error
occurs. Is the File.OpenWrite a safer method?
Thank you
VB.Net.
Using sw As StreamWriter = New StreamWriter(fName)
For Each row As DataRow In ds.Tables(0).Rows
For i As Integer = 0 To (ds.Tables(0).Columns.Count - 1)
col = row(i).ToString.Replace(","c, " "c) 'make sure no extra
commas
If (i < (ds.Tables(0).Columns.Count - 1)) Then
sw.Write(col & ",")
Else
sw.Write(col)
End If
Next
sw.WriteLine()
Next
sw.Close()
End Using
seems very simple, but I am told this method leaves a file open if an error
occurs. Is the File.OpenWrite a safer method?
Thank you