Using writer As New StreamWriter(filePath)
For rowIndex = 0 To table.Rows.Count - 1
Dim row = table.Rows(rowIndex)
If rowIndex > 0 Then
'Add a line break before all but the first line.
writer.WriteLine()
End If
For columnIndex = 0 To table.Columns.Count - 1
If columnIndex > 0 Then
'Add a comma before all but the first field.
writer.Write(",")
End If
'Write out the data for the current field.
writer.Write(row(columnIndex))
Next
Next
End Using
Using writer As New IO.StreamWriter(filePath)
For Each row As DataRow In table.Rows
writer.WriteLine(String.Join(",", row.ItemArray))
Next
End Using