Access Information --- Text File

reubenfoo

Member
Joined
Nov 25, 2008
Messages
18
Location
Singapore
Programming Experience
Beginner
Hi all,

how do i convert field information from an access database into a text file format,

I'm supposed to dass a "@" between every field to act as a delimiter.

Attached are before
before.jpg

and after pictures
after.JPG
 
Here's a method I use to write a DataTable to a delimited file.

VB.NET:
CreateDelimitedFile(ds.Tables("File"), "C:\Temp\MyFile.txt", "@", True)

VB.NET:
	Public Sub CreateDelimitedFile(ByVal dt As DataTable, ByVal filePath As String, ByVal fileDelimiter As String, ByVal writeHeader As Boolean)

		Dim sw As StreamWriter = New StreamWriter(filePath, False)
		Dim ColumnCount As Integer = dt.Columns.Count

		If writeHeader = True Then
			For i As Integer = 0 To ColumnCount - 1
				sw.Write(dt.Columns(i))
				If i < ColumnCount - 1 Then
					sw.Write(fileDelimiter)
				Else
					sw.Write(sw.NewLine)
				End If
			Next
		End If

		For Each row As DataRow In dt.Rows
			For i As Integer = 0 To ColumnCount - 1
				If Not row.IsNull(i) Then
					sw.Write(row.Item(i).ToString())
				End If
				If i < ColumnCount - 1 Then
					sw.Write(fileDelimiter)
				Else
					sw.Write(sw.NewLine)
				End If
			Next
		Next

		sw.Close()

	End Sub

There are plenty of guides on this board on how to fill a DataTable from Access.
 
Back
Top