Private Sub btnExport_Click() Handles btnExport.Click
ExportTableToTabDelimitedFile(strFileNameAndPath, myDataset.myTable, True)
End Sub
Public Sub ExportTableToTabDelimitedFile(ByVal strFile As String, ByVal dtSource As DataTable, Optional ByVal blnHeader As Boolean = True)
Dim strBdr As New System.Text.StringBuilder
Using swExport As New StreamWriter(strFile)
'Output column names in header row
If blnHeader = True Then
For Each colHeader As DataColumn In dtSource.Columns
strBdr.Append(colHeader.ColumnName)
strBdr.Append(ControlChars.Tab)
Next colHeader
swExport.WriteLine(strBdr.ToString)
strBdr.Remove(0, strBdr.Length)
End If 'blnHeader
For Each row As DataRow In dtSource.Rows
For Each col As DataColumn In dtSource.Columns
strBdr.Append(row(col).ToString)
strBdr.Append(ControlChars.Tab)
Next col
swExport.WriteLine(strBdr.ToString)
strBdr.Remove(0, strBdr.Length)
Next row
End Using 'swExport
End Sub