title: VB.Net sql data to text file
body: <p>Am Trying to write the data that is retrevied from the sql query into a text file in visual basic 2012 here is some code i have just need a push in the right direction </p>
  
  <pre><code>Imports System.Data.SqlClient
  Imports System.IO
  
  Public Class frmResults
      Dim cn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\bryan\Documents\TeamGFinalProject\BookCollection.MDF;Integrated Security=True;Connect Timeout=30")
      Dim cmd As New SqlCommand
      Dim dr As SqlDataReader
      Dim table As New DataTable("sales")
  
  Private Sub frmResults_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      cmd.Connection = cn
  End Sub
  
  Private Sub BtnReport_Click(sender As Object, e As EventArgs) Handles BtnReport.Click
      cn.Open()
      cmd.CommandText = "select * from sales  where ord_date BETWEEN '" &amp; dtpStart.Text &amp; "' AND '" &amp; dtpEnd.Text &amp; "' Order BY ord_date;"
  
      Using sw As StreamWriter = New StreamWriter("Dates.txt")
          Dim reader As SqlDataReader = cmd.ExecuteReader()
  
          sw.WriteLine(reader)
          reader.Close()
      End Using
  
      cn.Close()
  End Sub
  
  End Class
  </code></pre>