title: Exporting data from multiple SQL tables to different flat files using SSIS Script Task
body: <p>I am trying to create a datagrid and export the contents to a text file using VB.NET and I am doing this inside an SSIS script task in order to automate the process to export a dynamic table to text file. I don't get any error and the files are created but the files are empty. </p>
  
  <p>What am I doing wrong here in this code?</p>
  
  <pre><code>Public Sub Main()
  
      Dim FName As String = "D:\test.TXT"
  
      ''''''''''''''''''''''''''''''''''''''''''
      If File.Exists(FName) Then
          File.Delete(FName)
      End If
      ''''''''''''''''''''''''''''''''''''''''''
  
      Dim myConnection As OleDbConnection = New OleDbConnection("Data Source=localhost;Provider=SQLNCLI10;Initial Catalog=AdventureWorksDW2008R2;Integrated Security=SSPI;")
      Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table")
      Dim ds As DataSet = New DataSet
  
      da.Fill(ds, "Test")
  
      Dim DataGrid1 As New DataGrid
      DataGrid1.DataSource = ds.DefaultViewManager
      Dim DataGridView1 As New DataGridView
  
      DataGridView1.DataSource = ds
  
      Dim dgvc As DataGridViewCell
      Dim sw As New System.IO.StreamWriter(FName)
  
      For Each dgvr As DataGridViewRow In DataGridView1.Rows
  
          Dim intCellCount As Integer = dgvr.Cells.Count
          Dim intCounter As Integer = 1
  
          For Each dgvc In dgvr.Cells()
              If intCounter &lt;&gt; intCellCount Then
                  sw.Write(dgvc.Value.ToString &amp; "|")
              Else
                  sw.WriteLine(dgvc.Value.ToString)
              End If
  
              intCounter += 1
          Next
      Next
  
      Dts.TaskResult = ScriptResults.Success
  
  End Sub
  </code></pre>