Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2005, 05:38 PM
Registered User
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old January 4th, 2005, 11:01 AM
Registered User
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks....but I figured it out. My field name 'text' was throwing it off. Keyword maybe?

Oh well it works....thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Read CSV file - Save Columns into Rows pintoo BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 August 20th, 2008 09:01 AM
Export data in to csv file from asp.netpage madhusrp ASP.NET 1.0 and 1.1 Professional 1 June 9th, 2006 09:15 AM
csv file into access table with vba Perseus Access VBA 2 September 14th, 2005 02:57 PM
read csv file ccc_storage Classic ASP Professional 2 August 21st, 2004 04:39 AM
Read-Only Access phungleon Access 14 January 29th, 2004 03:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.