I have a database in Access and I need to export that information into a text file The problem that I have is that it is not exported in the correct format. This is an example of the text file that is been exported:
info|info1|info3|info4|info5|info6|info7|info8| <this is the wrong format
info|info1|info3|info4|info5|info6|info7|info8 <this is the correct format
Dim connetionString As String
Dim cnn As OleDbConnection
connetionString = "connection string.accdb;"
cnn = New OleDbConnection(connetionString)
Dim dtResult As New DataTable
'Change the query
Dim dataAdap As New OleDbDataAdapter("SELECT * FROM table", cnn)
'Change the path to your desired path
Dim RUTA As String = "path were i want to put the text file\"
Dim ARCHIVOTXT As String = "filename of the text file.txt"
If Not Directory.Exists(RUTA) Then
Dim writer As New StreamWriter(RUTA + ARCHIVOTXT)
Dim sb As New StringBuilder
For Each row As DataRow In dtResult.Rows
sb = New StringBuilder
For Each col As DataColumn In dtResult.Columns
sb.Append(row(col.ColumnName) & "|")
Catch ex As Exception
If Not writer Is Nothing Then writer.Close()
For Each col As DataColumn In dtResult.Columns sb.Append(row(col.ColumnName) & "|") Next writer.WriteLine(sb.ToString())
You could just use:
String.Join("|", row.ItemArray) concatenates the
ToString() result of each value held by the row separating the values with a "|".