Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO TextStream Help

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

I am using the ADO textstream to read a .txt file and from that insert data into my database. This is working well if i need to skip only one line.

The issue i have is the text file contains either one or two lines at the begining that i need to skip. unfortunatly i won't know which it is without reading the first two lines and checking them for a value. If they both contain the word "select" skip them both if only the first does then skip just that line.

Is there a way i can do this? Any help would be great.

Thank you.
 
you need two variables to store data for both lines for later need. then start your loop from the third record on and do something with the data in record one and two.
readline first record
rec1_data = MyFile.ReadLine
rec2_data = MyFile.ReadLine

if instr(rec1_data, "select") > 0 then
do nothing
end if
if instr(rec1_data, "select") > 0 and
instr(rec2_data, "select") > 0 then
do nothing
end if

do something with the results of above data

Do While MyFile.AtEndOfStream <> True
ReadLineTextFile = MyFile.ReadLine

do something with the data that you read

Loop


 
taking wvdba's code a little futher, you don't need to check it at the beginning, just check it within the do-while loop...

this will assume you only want to check the first two lines for the word "select". If you want to omit all lines with the word "select" get rid of the "intLine" var and condition.
Code:
<%
intLine = 1
Do While MyFile.AtEndOfStream <> True
	ReadLineTextFile = MyFile.ReadLine
	' this says that if you are on line 1 or 2 and the word "select" is not in the line do something
	if intLine <= 2 and instr(ReadLineTextFile,"select") < 0 then
		'do something with the data that you read
	end if
	intLine = intLine + 1
 Loop
 %>

There are a lot of posters on this board that are good with Regular Expressions, one of them may be able to post it using that method...I can't write them for the life of me....

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
if you're porting the entire thing into say a blob/memo field you could use regex replace for the entire line(s)

"$\*+select\*+\n"

or something like that my regex sux

and pull the entire blob

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
oops forgot to note that's inreference to a FSO/ADO.readall

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top