Text files

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
 
S

Sueffel

Ruslan Shlain said:
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
Off the hip....
Forget the Connection and DataAdapter. Create a DataTable, then, using a
rows and column object, add you're rows. To step backward, make a string(),
read each line in and use a Split function to seperate those suckers out,
then add them to the table, adding the table to the DataSet. That would be
my solution.

HTH
Sueffel
 
P

Paul Clement

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

You might want to post the first ten or twenty lines of your text file if possible.

BTW, if the delimiter is a pipe character then you will need to change the Format argument in your
schema.ini file to:

Format=Delimited(|)


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top