ASP and INSERT SQL statement

Basically when i do a response.write to my query string, then copy it and run it in my Access database as a SQL statement it works. However when i try and run it from my ASP page i get the error:

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.

but the syntax can't have a error because it works when i run it on the database it works.

my code is:

[code]
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("database.mdb")

Set connection = Server.CreateObject("ADODB.Connection")
connection.Mode = 3 'allow writable
connection.Open(sConnString)


strQuery = "INSERT INTO Customer (username, password, Customer_FirstName, Customer_Surname, Address1, Address2, Town, Postcode, Tel, Email, SortCode, AccountNumber, PaymentTypeId) VALUES ( 'robbie', 'password', 'name', 'name1', 'add1', 'add2', 'town', 'post', 'tel', 'email', '111111', '33232', '1'); "

' Response.Write(strQuery)
connection.Execute(strQuery)
[/code]

The only row missing is the primary key and that is of type auto number.

Thanks in advance.

*Ribbleton_

Comments

  • : Basically when i do a response.write to my query string, then copy it and run it in my Access database as a SQL statement it works. However when i try and run it from my ASP page i get the error:
    :
    : Error Type:
    : Microsoft JET Database Engine (0x80040E14)
    : Syntax error in INSERT INTO statement.
    :
    : but the syntax can't have a error because it works when i run it on the database it works.
    :
    : my code is:
    :
    : [code]
    : sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    : "Data Source=" & Server.MapPath("database.mdb")
    :
    : Set connection = Server.CreateObject("ADODB.Connection")
    : connection.Mode = 3 'allow writable
    : connection.Open(sConnString)
    :
    :
    : strQuery = "INSERT INTO Customer (username, password, Customer_FirstName, Customer_Surname, Address1, Address2, Town, Postcode, Tel, Email, SortCode, AccountNumber, PaymentTypeId) VALUES ( 'robbie', 'password', 'name', 'name1', 'add1', 'add2', 'town', 'post', 'tel', 'email', '111111', '33232', '1'); "
    :
    : ' Response.Write(strQuery)
    : connection.Execute(strQuery)
    : [/code]
    :
    : The only row missing is the primary key and that is of type auto number.
    :
    : Thanks in advance.
    :
    : *Ribbleton_
    :

    You mean coloumn?

    Try including that in there and setting the value as '' for it.
    I think that solved a similar problem I had...

    -( Aaron )-

    "Alcohol aint the answer, but atleast you forget the question"

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion