473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

select on textfile question

Hi, I'm creating an import module to read data from old textfiles, run some
calculations on them and save them to sql server. I've figured out how to do
a select on textfile using a schema.ini file (my textfile is delimeted by a
| )
But I've got on problem remaining, below you can so two example rows out of
the textfile:

560000||TS|alu dak|0000000067|P400|20|7101|401|0|0|0|0|||||N|J

560039||KM|"De Gaer":
Partoens-Nijs|0000009001|P400|20|54|401|0|0|0|0|||||N|J

The first row is handled just fine, but if I read the second row into a
dataset, I get all NULLS after "De gaer", it doesn't read "De Gaer":
Partoens-Nijs as one column, it seems to trip on the "". Any hint or tip is
much appreciated. I also posted my connectionstring and schema.ini file
below.

Thanks in advance greetz Peter
Private ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\;Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Private conn As New OleDb.OleDbConnection(ConStr)
[TR028C.TXT]
ColNameHeader=False
CharacterSet=ANSI
Format=Delimited(|)
Col1=offnr Text
Col2=datum DateTime
Col3=calcu text
Col4=refer text
Col5=kltnr text
Col6=sercode text
Col7=kcode text
Col8=gcode text
Col9=ktype text
Col10=rp text
Col11=gp text
Col12=ri text
Col13=kw text
Col14=varia text
Col15=adrnr text
Col16=cdlev text
Col17=cdbet text
Col18=pt text
Col19=ofbev text
Nov 21 '05 #1
7 2506
Just for clarity, there's no vbcrlf after the : in my second example row,
that just happened with posting
560039||KM|"De Gaer":
Partoens-Nijs|0000009001|P400|20|54|401|0|0|0|0|||||N|J
Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Peter Proost" <pp*****@nospam.hotmail.com> schreef in bericht
news:us**************@TK2MSFTNGP09.phx.gbl... Hi, I'm creating an import module to read data from old textfiles, run some calculations on them and save them to sql server. I've figured out how to do a select on textfile using a schema.ini file (my textfile is delimeted by a | )
But I've got on problem remaining, below you can so two example rows out of the textfile:

560000||TS|alu dak|0000000067|P400|20|7101|401|0|0|0|0|||||N|J

560039||KM|"De Gaer":
Partoens-Nijs|0000009001|P400|20|54|401|0|0|0|0|||||N|J

The first row is handled just fine, but if I read the second row into a
dataset, I get all NULLS after "De gaer", it doesn't read "De Gaer":
Partoens-Nijs as one column, it seems to trip on the "". Any hint or tip is much appreciated. I also posted my connectionstring and schema.ini file
below.

Thanks in advance greetz Peter
Private ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\;Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Private conn As New OleDb.OleDbConnection(ConStr)
[TR028C.TXT]
ColNameHeader=False
CharacterSet=ANSI
Format=Delimited(|)
Col1=offnr Text
Col2=datum DateTime
Col3=calcu text
Col4=refer text
Col5=kltnr text
Col6=sercode text
Col7=kcode text
Col8=gcode text
Col9=ktype text
Col10=rp text
Col11=gp text
Col12=ri text
Col13=kw text
Col14=varia text
Col15=adrnr text
Col16=cdlev text
Col17=cdbet text
Col18=pt text
Col19=ofbev text

Nov 21 '05 #2
Peter,

Your question is not 100% clear for me, do you mean that it is a file with
by a | delimited fields.

Than the normal solution is to split it either with the net split or the
microsoft visual basic split. (AFAIK The last does not create extra space
fields and therefore is nicer to use)

Or do you mean that it is a classic textfile created in old punchcard style,
where than the MID from the Microsoft Visual Basic namespace or the
Substring from the Net Namespace is sufficient.

Cor
Nov 21 '05 #3
Hi Cor, it's a file containing records, and every column is seperated by a |
and every new row in the file is a new record. The file contains 1000 of
rows like my example row:

560000||TS|alu dak|0000000067|P400|20|7101|401|0|0|0|0|||||N|J

This row for example should become one record with 19 columns in an existing
sqlserver table.
I thought if I can do a select on the textfile it would be faster then
reading and splitting every row manualy (is this true?), but to get this to
work I needed a schema.ini file because | is used as seperator.
So I created this routine and the following schema.ini file. Everything
works just fine except when I've got double quotes in one of the colums, for
example:

560039||KM|"De Gaer":|0000009001|P400|20|54|401|0|0|0|0|||||N|J

then everything is ok, untill "De Gaer": if I for example read the record
into a datarow and check it's values I get this:

dr(0) = 560039
dr(1) = NULL
dr(2) = KM
dr(3) = "De Gaer"
dr(4) = NULL
dr(5) = NULL
dr(6) = NULL
and so on

It seems that it can't handle the double quotes, because it gives all NULL
after the last double quote. I hope it's a bit more clear now. But I've got
another question, was I right think that doing selects on textfiles is
faster then reading and splitting them myself?

Thanks and greetz Peter

Private sub read_file

Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\;Extended Properties=""Text;HDR=No;FMT=Delimited"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet

da.SelectCommand.CommandText = "Select * from tr028c.txt"
da.Fill(ds, "TextFile")

End Sub

Schema.ini:
[TR028C.TXT]
ColNameHeader=False
CharacterSet=ANSI
Format=Delimited(|)
Col1=offnr Text
Col2=datum DateTime
Col3=calcu text
Col4=refer text
Col5=kltnr text
Col6=sercode text
Col7=kcode text
Col8=gcode text
Col9=ktype text
Col10=rp text
Col11=gp text
Col12=ri text
Col13=kw text
Col14=varia text
Col15=adrnr text
Col16=cdlev text
Col17=cdbet text
Col18=pt text
Col19=ofbev text


"Cor Ligthert [MVP]" <no************@planet.nl> schreef in bericht
news:#Q**************@TK2MSFTNGP12.phx.gbl...
Peter,

Your question is not 100% clear for me, do you mean that it is a file with
by a | delimited fields.

Than the normal solution is to split it either with the net split or the
microsoft visual basic split. (AFAIK The last does not create extra space
fields and therefore is nicer to use)

Or do you mean that it is a classic textfile created in old punchcard style, where than the MID from the Microsoft Visual Basic namespace or the
Substring from the Net Namespace is sufficient.

Cor

Nov 21 '05 #4
Peter,

I have thought a long while as you, however I would now just split them and
use the indexer to get the fields from the array.

Have a look at those two different split methods.

http://msdn.microsoft.com/library/de...splittopic.asp

http://msdn.microsoft.com/library/de...vafctsplit.asp

Just try them and than I think that you take the second one.

I hope this helps,

Cor


Cor
Nov 21 '05 #5
Hi Cor ,

I've always used the second one, but can I conclude that reading and
splitting the file manualy is faster then performing multiple selects on a
textfile?

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Cor Ligthert [MVP]" <no************@planet.nl> schreef in bericht
news:ec*************@TK2MSFTNGP14.phx.gbl...
Peter,

I have thought a long while as you, however I would now just split them and use the indexer to get the fields from the array.

Have a look at those two different split methods.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemstringclasssplittopic.asp
http://msdn.microsoft.com/library/de...us/vblr7/html/
vafctsplit.asp
Just try them and than I think that you take the second one.

I hope this helps,

Cor


Cor

Nov 21 '05 #6
Peter,

Did you try it, how many nano seconds you think it will be.

Assuming that your textfile is not something as 10Mb

I think that it is faster and at least consuming less memory. You can split
it row by row and than instert them using the SQL insert with parameters and
execute nonquery into your database.

(You can index the parameters probably the same as your fields and than just
a simple loop).

I hope this helps,

Cor
Nov 21 '05 #7
Hi Cor,

I haven't timed it, but I think I don't need to because I just ran a test
testing both methods, and manualy reading the file was definite faster.

Greetz and thanks Peter
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Hans A | last post by:
I have a textfile "textfile.txt" containing a list of words. There is one word on each line. I want to pick two random lines from this textfile, and I have tried to do something like: //Loading...
1
by: Larry Rekow | last post by:
I have a report that's created each day as a flat textfile. Because I came from the Access world, I created a macro that imports it with a schema that gives meaningful names to the various...
8
by: andreas | last post by:
A textfile can have different formats like ANSI,UTF8, Unicode ... Using streamreader for a textfile can have different results for chars like é,à,è....depending of the fileformat. To solve this...
3
by: Billy | last post by:
I do a SELECT * from table command in an ASP page to build a text file out on our server, but the export is not to allow a field name rows of records. The first thing I get is a row with all the...
1
by: Billy | last post by:
I do a SELECT * from table command in an ASP page to build a text file out on our server, but the export is not to allow a field name rows of records. The first thing I get is a row with all the...
1
by: kachokaratz | last post by:
well i have a problem in my project..since the contents of my textfile is too long, i was wondering how to output the textfile in such a way that you can divide the contents to be able to output...
14
by: blumen | last post by:
Hi all, I'm a newbie in VB.Net Programming.. Hope that some of you can help me to solve this.. I'm working out to read,parse and save textfile into SQL Server. The textfile contains thousands...
1
by: saytri | last post by:
Hi i'm a student studying java (i'm still a beginner). i have a project were i have to do a quiz with a set of questions. So i think that i have to type the questions in a textfile for example in...
1
by: asedt | last post by:
With my Excel macro and two text files I want to create a new textfile containing the first textfile then text from the sheet and then the second textfile. My problem is that i don't know how to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.