Re: Syntax error in INSERT INTO statement.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 06/25/04


Date: Fri, 25 Jun 2004 12:00:24 -0400

SAM wrote:
> Hi All,
> When I run the following code,
> set cn=server.CreateObject("ADODB.Connection")
> SQL2="INSERT into [ShoppingCart]([SCSessionID],[ProductID], [PPrice])"
> SQL2=SQL2 + " VALUES ( "&Session.SessionID&" , '"&ProductID&"' ,
> "&PPrice&")"
> cn.Execute SQL2
>
> I got syntax error in INSERT INTO statement. I don't what's wrong.
> It's killing me. If anyone can help, it will be appreciated. By the
> way, SCSessionID is number, ProductID is text and PPrice is currency.
> I am using Access as DB.
>
> Thanks.

The first step when debugging sql syntax errors is to look at the query as
the database is seeing it. The best way to do that is to response.write it:

Response.Write SQL2
Response.End

Run the page and look at the sql statement in the browser window. If the
problem does not stick out like a sore thumb, open your database in Access,
go to the Queries tab, start a new query in Design view, closing the Choose
Tables dialog without choosing a table, switch to SQL View, paste the
statement in from the browser window and try to run it. You should get a
better error message. If you still can't see what the problem is, show us
the sql statement.

Bob Barrows

-- 
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Relevant Pages

  • Re: Syntax error in FROM clause
    ... It appears that the maximum length of the SQL statement has been reached. ... "George wilson" wrote in message ... >><MS ACCESS MVP> ... >>> a "Syntax error in FROM clause" and is unable to view ...
    (microsoft.public.access.forms)
  • Re: INSERT command doesnt work in Access
    ... that OleDbException, that says "Syntax error in SQL statement". ... Lately I've tried simple OleDbCommand, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: How to update my access to current date??
    ... I try using the following sql statement.. ... > Syntax error in UPDATE statement. ... This email account is my spam trap so I ...
    (microsoft.public.inetserver.asp.general)
  • Re: rewrite QBE SQL statement
    ... I am now getting a syntax error that tells me that I am missing an operator ... Is there a way to rewrite this as nested subqueries in such a way ... I am trying to write a SQL statement based on a SQL statement from the ... I am trying to rewrite this into workable SQL that I can pass as string ...
    (microsoft.public.access.modulesdaovba)
  • Re: Change table date/time field to text field in code
    ... That means your SQL statement is not correct. ... > When I try this method, I am getting error 3293 Syntax error in ALTER ... >> Dim strSql As String ...
    (comp.databases.ms-access)