ASP to read .CSV into Access
Okay, I am trying to read a .csv file line by line and insert the records into a database through ASP. I can Response.Write sSeg() to the screen, but when I try to insert the records into the database it gives me:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
/technology/test/gls/import_action.asp, line 32
It works fine if I just insert the first field (sequence), but when I try to insert all four fields it gives me the error. Here is my code:
<%
'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="test.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,",")
dim strsql
strsql="INSERT INTO CSV (Sequence, Text, Name, Grade)"
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
%>
Sequence, Text, Name, and Grade are all text fields in my database. The .CSV is comma delimmited.
If anyone has any suggestions I would really appreciate it.
Thanks
|