title: Is there a way i can write to CSV Faster?
body: <p>I have a for Loop that grabs data from a data table and writes to a text file, as csv. This works great for small csv files but becomes very very slow when writing bigger csv files, say 5000 records takes 2 minutes. Is there a better way I can do this?</p>
  
  <p>Thanks.</p>
  
  <pre><code>Dim dt As New DataTable()
   dataadapter.Fill(dt)
  
  For i As Integer = 0 To dt.Rows.Count - 2
  
                  For j As Integer = 0 To dt.Columns.Count - 1
                      writer.Write(dt.Rows(i).Item(j).ToString().Trim() &amp; ",")
  
                  Next
  
              Next
  </code></pre>