p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 3rd, 2005, 05:38 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: , , .
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 4th, 2005, 11:01 AM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: , , .
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 10:01 AM
Export data in to csv file from asp.netpage madhusrp ASP.NET 1.0 and 1.1 Professional 1 June 9th, 2006 10:15 AM
csv file into access table with vba Perseus Access VBA 2 September 14th, 2005 03:57 PM
read csv file ccc_storage Classic ASP Professional 2 August 21st, 2004 05:39 AM
Read-Only Access phungleon Access 14 January 29th, 2004 03:04 PM



All times are GMT -4. The time now is 12:25 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc