andreathedove Posted February 27, 2008 Share Posted February 27, 2008 --------------------------------------------------------------------------------Hello,I have problem with this script.Here you can find the complete csv file:http://www.allinonenet.it/prezzi_PAZZI/csvcart.csvAnd the script is: <%@ Language="VBScript" %><% 'CONNECT TO THE DATABASE set objconn = Server.CreateObject("ADODB.Connection") objconn.Provider="Microsoft.Jet.OLEDB.4.0" objconn.Open Server.MapPath("../mdb-database/csv.mdb") csv_to_read="csvcart.csv" set fso = createobject("scripting.filesystemobject") set act = fso.opentextfile(server.mappath(csv_to_read)) dim sline dim sSeg Do Until act.AtEndOfStream sline=act.readline sSeg=split(sline,vbTab) dim strsql strsql="INSERT INTO CSV (CompanyID,CompanyName)" strsql=strsql & "VALUES('"&sSeg(0)&"','"&sSeg(1)&"')" objconn.execute strsql loop act.close set act=nothing 'CLOSE THE CONNECTION AND CLEAN UP objconn.close set objconn=nothing%> And the error:http://www.allinonenet.it/prezzi_PAZZI/csv.aspThanks,Andrea Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2008 Share Posted February 27, 2008 Your CSV file isn't a CSV file. Open it in a text editor or Excel and take a look at it, it's not formatted as CSV data. The error is because you're trying to access element 2 of a line, but the first line only has 1 element. You split up the CSV file on lines, but the first "CSV element" has several line breaks in it. So when you split it up on lines you are only reading part of the first value for the entire line, then trying to split that up on a tab character, but there's not a tab character there until later on. You would need to remove all of the extra line breaks in the CSV file to make it valid, so that the only place that newline characters show up is to separate rows in the CSV file. Link to comment Share on other sites More sharing options...
andreathedove Posted February 27, 2008 Author Share Posted February 27, 2008 Your CSV file isn't a CSV file. Open it in a text editor or Excel and take a look at it, it's not formatted as CSV data. The error is because you're trying to access element 2 of a line, but the first line only has 1 element. You split up the CSV file on lines, but the first "CSV element" has several line breaks in it. So when you split it up on lines you are only reading part of the first value for the entire line, then trying to split that up on a tab character, but there's not a tab character there until later on. You would need to remove all of the extra line breaks in the CSV file to make it valid, so that the only place that newline characters show up is to separate rows in the CSV file.Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.