andreathedove Posted June 15, 2008 Share Posted June 15, 2008 Hola.I have a question on Importing CSV to Access.I have this csv file:http://www.allinonenet.it/FINO-clickpoint.csvI have this code <%@ Language="VBScript" %><% 'CONNECT TO THE DATABASE set objconn = Server.CreateObject("ADODB.Connection") objconn.Provider="Microsoft.Jet.OLEDB.4.0" objconn.Open Server.MapPath("csv.mdb") csv_to_read="FINO-clickpoint.csv" set fso = createobject("scripting.filesystemobject") set act = fso.opentextfile(server.mappath(csv_to_read),1,Fal se) dim sline dim sSeg Do Until act.AtEndOfStream sline=act.readline sSeg=split(sline,",") <-- Here. I don't know what to replace. dim strsql strsql="INSERT INTO CSV (CompanyID, CompanyName, Address, Country)" strsql=strsql & "VALUES('"&sSeg(0)&"', '"&sSeg(1)&"', '"&sSeg(2)"', '"&sSeg(3)&"')" objconn.execute strsql loop act.close set act=nothing 'CLOSE THE CONNECTION AND CLEAN UP objconn.close set objconn=nothing%> How can I resolve the problem ?Thanks,Andrea Link to comment Share on other sites More sharing options...
andreathedove Posted June 17, 2008 Author Share Posted June 17, 2008 Hola.I have a question on Importing CSV to Access.I have this csv file:http://www.allinonenet.it/FINO-clickpoint.csvI have this code<%@ Language="VBScript" %><% 'CONNECT TO THE DATABASE set objconn = Server.CreateObject("ADODB.Connection") objconn.Provider="Microsoft.Jet.OLEDB.4.0" objconn.Open Server.MapPath("csv.mdb") csv_to_read="FINO-clickpoint.csv" set fso = createobject("scripting.filesystemobject") set act = fso.opentextfile(server.mappath(csv_to_read),1,Fal se) dim sline dim sSeg Do Until act.AtEndOfStream sline=act.readline sSeg=split(sline,",") <-- Here. I don't know what to replace. dim strsql strsql="INSERT INTO CSV (CompanyID, CompanyName, Address, Country)" strsql=strsql & "VALUES('"&sSeg(0)&"', '"&sSeg(1)&"', '"&sSeg(2)"', '"&sSeg(3)&"')" objconn.execute strsql loop act.close set act=nothing 'CLOSE THE CONNECTION AND CLEAN UP objconn.close set objconn=nothing%> How can I resolve the problem ?Thanks,Andrea Hello,I try:<%@ 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="FINO-clickpoint.csv" set fso = createobject("scripting.filesystemobject") set act = fso.opentextfile(server.mappath(csv_to_read),1,False) dim sline dim sSeg Do Until act.AtEndOfStream sline=act.readline sSeg=split(sline,";") dim strsql strsql="INSERT INTO CSV (id, categoria)" 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%> but it give me this errorhttp://www.allinonenet.it/csv.aspwhy?Andrea Link to comment Share on other sites More sharing options...
justsomeguy Posted June 18, 2008 Share Posted June 18, 2008 Because it found a line that doesn't have any commas in it. You should check how many elements you have after the split before trying to use them. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.