Import text files

  • Thread starter Thread starter Ruslan Shlain
  • Start date Start date
R

Ruslan Shlain

I have a | (pipe) delimited file that i need to import in to a Dataset. With
code below i get 7 items in the first column of each row and the rest is
empty. PLEASE HELP

Below if the code that does it.

For it to work i needed an ini file with columns defined and at the top of
the ini these options are set

[c125788_1_fi_011404_001.txt]
ColNameHeader=False
Format=CSVDelimited
MaxScanRows=25
CharacterSet=ANSI


<-----------------VB Code------
Dim FilePath As String = "C:\ftproot\TOG\"

Dim Conn As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & FilePath & ";Extended Properties=""text;HDR=NO;FMT=Delimited""")

Dim Comm As New System.Data.OleDb.OleDbDataAdapter("select * from
c125788_1_fi_011404_001.txt", Conn)

Dim DS As New DataSet

Try

Comm.Fill(DS)

Catch e As Exception

End Try

Conn.Close()

Dim i As Integer = DS.Tables(0).Rows.Count

End Sub
 
A CSV file is Comma Separater Values.
It is just a delimited file where the delimiter is defined as a comma.

Since your delimiter is a pipe | not a comma try this:
Format=Delimited(|)



In case it fails:
The delimiter may need to be in quotes:
Format=Delimited("|")
 
Back
Top