'--this code works but only reads text into one column when contains multiple
cols
Dim ds1x As New DataSet
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended
Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn1x As New OleDb.OleDbConnection(ConStr)
Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
dax1.Fill(ds1x, "tbl0")
datagridview1.DataSource = ds1x.Tables("tbl0")
-------------------------------------------------------
The above code works fine for reading text from a textfile and adding it to
a datagridview. My problem is that I have mutiple columns delimited by a
pipe '|', and the code above is not delimiting the text. I get it all in one
column. How to make it delimit the text into multiple columns?
Thanks,
Rich
mark.milley@binaryswitch.com - 02 Jul 2007 19:10 GMT
Hi Rich -
It doesn't look like you ever specified your delimiter.
Try changing FMT=Delimited to FMT=Delimited(<delimiter>) or in your
case, FMT=Delimited(|)
Good Luck,
-Mark
Rich - 02 Jul 2007 23:08 GMT
thanks for your reply. Anyway, I am using '|' as the delimiter. So I tried
...;Extended Properties=""Text;HDR=No;FMT=Delimited(|)\"""
and
...;Extended Properties=""Text;HDR=No;FMT=Delimited('|')\"""
But no delimiting ensued. However, I created a csv file - by hand - and
that did come in delimited with
...;Extended Properties=""Text;HDR=No;\"""
The only problem is in writing to a csv file.
Dim oWrite As StreamWriter
oWrite = File.AppendText("C:\1A\testabc1x.csv")
oWrite.WriteLine("A" & vbTab & "B")
oWrite.Close()
when I open the csv file, I don't get 2 columns with oWrite.WriteLine("A" &
vbTab & "B"). I used to be able to write VBA code like that, and it would
have 2 columns. Any ideas?
> Hi Rich -
>
[quoted text clipped - 6 lines]
>
> -Mark
Paul Clement - 03 Jul 2007 15:31 GMT
¤ '--this code works but only reads text into one column when contains multiple
¤ cols
¤
¤ Dim ds1x As New DataSet
¤ Dim ConStr As String = _
¤ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended
¤ Properties=""Text;HDR=No;FMT=Delimited\"""
¤
¤ Dim conn1x As New OleDb.OleDbConnection(ConStr)
¤ Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
¤ dax1.Fill(ds1x, "tbl0")
¤ datagridview1.DataSource = ds1x.Tables("tbl0")
¤
¤ -------------------------------------------------------
¤ The above code works fine for reading text from a textfile and adding it to
¤ a datagridview. My problem is that I have mutiple columns delimited by a
¤ pipe '|', and the code above is not delimiting the text. I get it all in one
¤ column. How to make it delimit the text into multiple columns?
For a column delimiter other than a comma you either need to change a Registry setting or use a
schema.ini file.
[testabc1x.txt]
ColNameHeader=False
CharacterSet=ANSI
Format=Delimited(|)
Paul
~~~~
Microsoft MVP (Visual Basic)
Rich - 03 Jul 2007 16:04 GMT
Thank you for your reply. I have seen several examples on the web suggesting
the same thing as you about using an schema.ini file. This seems the way to
go except that I can't figure out how this file is used. Ex: I write my
OleDBDataAdapter code. I place the schema.ini file in the same directory as
the text file I want to read. How does the schema.ini file get
invoked/implemented in the OleDBDataAdapter code? None of the examples I saw
on the web showed where the schema.ini file was referenced.
> ¤ '--this code works but only reads text into one column when contains multiple
> ¤ cols
[quoted text clipped - 26 lines]
> ~~~~
> Microsoft MVP (Visual Basic)
Paul Clement - 05 Jul 2007 15:34 GMT
¤ Thank you for your reply. I have seen several examples on the web suggesting
¤ the same thing as you about using an schema.ini file. This seems the way to
¤ go except that I can't figure out how this file is used. Ex: I write my
¤ OleDBDataAdapter code. I place the schema.ini file in the same directory as
¤ the text file I want to read. How does the schema.ini file get
¤ invoked/implemented in the OleDBDataAdapter code? None of the examples I saw
¤ on the web showed where the schema.ini file was referenced.
¤
It's automatic. The Text ISAM driver will look for the schema.ini file and search for an entry (like
the one I posted in my prior response) that corresponds to the text file that is being opened.
Paul
~~~~
Microsoft MVP (Visual Basic)
Rich - 06 Jul 2007 18:54 GMT
Thanks Very much
> ¤ Thank you for your reply. I have seen several examples on the web suggesting
> ¤ the same thing as you about using an schema.ini file. This seems the way to
[quoted text clipped - 11 lines]
> ~~~~
> Microsoft MVP (Visual Basic)