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--
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--