Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set delimiter using Microsoft Text Driver

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hi

I currently have a form that writes data to a text file using the code below. and code to read data (below the following code) using Microsoft Text Driver. Currently it could only read a comma delimiter but when I change it to a semi colon or anything else it doesn't accept it is there anyway I could setup a delimiter to read data from the text file.
Thanks

--Code to write data--
Dim sw As StreamWriter
Try
With SaveFileDialog1
.FileName = Filename
.Filter = "Text File (*.txt)|*.txt|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
Filename = .FileName
sw = New StreamWriter(Filename)
sw.WriteLine("txtCo_Name;txtCo_Address;)
sw.WriteLine(Me.txtCo_Name.Text & " ;" & _
Me.txtCo_Name.Text)


--Code ended --


--Code to read data--
Dim Conn As System.Data.Odbc.OdbcConnection
Dim dt As New DataTable

Dim da As System.Data.Odbc.OdbcDataAdapter
Dim strConnstr, strImportFolder, strFilename As String

Try
With OpenFileDialog1
.Filter = "Text files(*.txt)|*.txt|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
Filename = .FileName
strImportFolder = Path.GetPathRoot(Filename)
strFilename = Path.GetFileName(Filename)
'strFilename = Path.GetFileNameWithoutExtension(Filename) & "#txt"
strConnstr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & strImportFolder & "\;FMT=Delimited';'"

Conn = New Odbc.OdbcConnection(strConnstr)

da = New Odbc.OdbcDataAdapter("Select * from[" + strFilename + "]", Conn)

da.Fill(dt)
Me.txtCo_Name.Text = (dt.Rows(0).Item(0).ToString)

--Code Ended--


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top