...

View Full Version : 0x80040E14 Syntax error in INSERT INTO statement.



BarrMan
02-05-2005, 08:23 AM
Hi.

error:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
/bookstore/addtobasket.asp, line 11

Code:

<%
dim book_id
Request.QueryString("book_id")

dim conn
set conn=server.CreateObject("ADODB.connection")
conn.Open "dsn=bookstore"

conn.Execute "insert into basket (book_id, visitor_id) select " & book_id & ", " &_
Session("visitor_id")

conn.Close
set conn=nothing

Response.Redirect "showbasket.asp"
%>

Thx.

jaywhy13
02-06-2005, 04:34 AM
Here's my take:

I could be wrong but....

dim book_id
Request.QueryString("book_id")

I think what you meant to do was assign the result of the queryString to book_id like so:

dim book_id
book_id=Request.QueryString("book_id")

Could be wrong? :eek: U tell me? Was that the problem?
Coz if you have assigned a value to the book_id where I see u attempting to insert into your table... you might have been trying to enter blank data into a "zero-length not allowed" field

Secondly... this what you have for tha insert line:

conn.Execute "insert into basket (book_id, visitor_id) select " & book_id & ", " &_
Session("visitor_id")


I'm not sure wot that code is supposed to do, but if its a simple insert it should read (if that book_id and visitor_id are text fields):

conn.Execute "insert into basket (book_id, visitor_id) values "('" & book_id & "','" & Session("visitor_id") & "')"


But if they were numeric fields.... lose the single quotes:

conn.Execute "insert into basket (book_id, visitor_id) values "(" & book_id & "," & Session("visitor_id") & ")"

BarrMan
02-06-2005, 03:57 PM
I solved my problem by adding [ ], [ ] to my code,

conn.Execute = "INSERT INTO basket ([book_id], [visitor_id]) select " & book_id & ", " & session("visitor_id")

ghell
02-07-2005, 08:46 AM
what the?!

anyone know why that fixed it? i thought that was just to do thinks like have a variable named date without it just running Date()

jaywhy13
02-07-2005, 11:40 AM
Yea :eek: I was SUPER surprised when I saw his response. As far as I kno. The only times that we are required to use the square brackets are when a reserved keyword was used for a field..... And I don't see either of those keywords here (http://support.microsoft.com/kb/q125948/).

Its interesting. I'll keep my ears open to see if anyone can explain why that worked.... I'm puzzled to my friend! :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum