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!

vbs file - using adodb rs to read a csv file

Status
Not open for further replies.

dotolee

Technical User
Jan 27, 2008
134
CA
i have a vbs file where i'm trying to read in a csv file.
my code (in part) looks like:

set cnn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
cnn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & csvfilepath & "Extended Properties=""text;HDR=Yes;"""
rs.open "select * from " & csvfilename, cnn, 3, 3

Do while rs.eof<> True
response.write rs.fields.item(2).name & " " & rs.fields.item(2).value
loop

When i run this file against a manually created CSV file (labelled "Good csv" below), everything works. The LOCATION field comes back appropriately. So for the first record, i get the value "R1"

However, if I replace the good csv with my other csv below, it only returns the numeric portion of the location field. So instead of returning "F1" , it returns "1". As a test, if i change the entire location field to be numeric, it works fine. If i change it to a string like "abc" nothing is returned.

Any help would be appreciated!!


Good csv
FILELOCATION,FILENAME,LOCATION,CATEGORY,GRAPHICTYPE,SYSTEM,DESCRIPTION
Water System 2/,Chiller.asp,R1,HVAC,E,CHW,"This is a description for this graphic"
Water System 2/,myChiller1.asp,R1,HVAC,E,CHW,"This is another description for a graphic"
Water System 2/,myChiller2.asp,R1,HVAC,E,CHW,"nothing useful"

bad csv
FILELOCATION,FILENAME,LOCATION,CATEGORY,GRAPHICTYPE,SYSTEM,DESCRIPTION
Aire/,Alarms.asp,F1,HVAC,E,REF,"Alarms"
Aire/,Main.asp,F1,HVAC,E,REF,""
Aire/,SB1 revamp.asp,,,,,
 
btw
i've checked both the good and bad csv files to compare white space, newlines, tabs etc and i cannot see anything wrong with the "bad" file.
thanks.
 
Well THAT'S weird... Pretty easy to reproduce too!

I would love to hear the full explanation of what is going on, but it appears that ADO is making assumptions about the data type, based on what values it sees??? But why does "F1" botch things up... but "R1", or "A1" for example, work?

One way around it is (if possible) surround text values in double-quotes.
 
That is interesting...if I do a TypeName for the value it shows as currency so I think guitarzan assumptions may be correct.

Create a Schema.ini file in the same place as your CSV file and put this as the content:

Code:
[bad.csv]
Format=CSVDelimited
Col1=FILELOCATION TEXT
Col2=FILENAME TEXT
Col3=LOCATION TEXT
Col4=CATEGORY TEXT
Col5=GRAPHICTYPE TEXT
Col6=SYSTEM TEXT
Col7=DESCRIPTION TEXT

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top