codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Insert data into Access Database  Archive Import (osk) at 10:50 on Monday, June 30, 2003
 

Trying to pass details from a form into an Access database. Although I get the following error:

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

I`ve checked the statement and I can`t really find any problems with the code. So could anyone please help me, I`m very very stuck...

asp page code -
<%
`Create object. In this case Connection to a database
Set Conn = Server.CreateObject("ADODB.Connection")

`Select provider
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
`Select data source.
`Server.MapPath function is equivalent to app.path function of VB
`It returns the directory in which the script is present
Conn.ConnectionString = "Data Source=" & Server.MapPath ("db/esurvedata.mdb")
`Open the connection
Conn.Open

Sub CheckValid(Str)
Str = Replace(Str, "`", "``")
If Str = "" THEN
Str = " "
End If
End Sub

strFname = server.HTMLencode(Request.Form("firstname"))
strSname = server.HTMLencode(Request.form("surname"))
strCname = server.HTMLencode(Request.form("companyname"))
strPosition = server.HTMLencode(Request.form("position"))
strEmail = server.HTMLencode(Request.form("email"))
strPhoneno = server.HTMLencode(Request.form("phoneno"))

Call CheckValid(strFname)
Call CheckValid(strSname)
Call CheckValid(strCname)
Call CheckValid(strPosition)
Call CheckValid(strEmail)
Call CheckValid(Phoneno)


strSQL="INSERT INTO esurvey(firstname, surname, companyname, position, email, phoneno) VALUES (` " & strFname & " ` , ` " & strSname & " ` , ` " & strCname & " ` , ` " & strPosition & " ` , ` " & strEmail & " ` , ` " & strPhoneno & " `)"

conn.execute strSQL
%>

osk

  Re: Insert data into Access Database  Yusairi at 10:53 on Monday, July 07, 2003
 

hi osk,

remark this function...

<%

`Call CheckValid(strFname)
`Call CheckValid(strSname)
`Call CheckValid(strCname)
`Call CheckValid(strPosition)
`Call CheckValid(strEmail)
`Call CheckValid(Phoneno)

%>
don`t need to check whether it contains value ` or ``.
hopefully it works.

"Gain More Knowledge"
http://www.vss.com.my


  Re: Insert data into Access Database  Archive Import (osk) at 10:56 on Monday, July 07, 2003
 

it`s all good, found out that the coloumn name `position` could not be used in the database, not entirely sure why that is the case but after changing the coloumn name the code works fine!lol

osk

  Re: Insert data into Access Database  Yusairi at 11:21 on Monday, July 07, 2003
 

try replace
position
with
[position]

maybe it`s work.


  Re: Insert data into Access Database  Archive Import (Joe) at 19:42 on Wednesday, July 30, 2003
 

Hi there, I keep getting the same error:

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

I`ve looked at my column headings and none of them seem to be one which is prohibited.

Here`s my code:

============================================================

` Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.Mappath("storeDB.mdb")& "; Jet OLEDB:Database Password="

` Add New User to Database
sqlString = "INSERT INTO Users ( " &_
"user_username, " &_
"user_password, " &_
"user_email, " &_
"user_street, " &_
"user_town, " &_
"user_county, " &_
"user_postcode, " &_
"user_cctype, " &_
"user_ccnumber, " &_
"user_ccexpires, " &_
"user_ccname, " &_
") VALUES ( " &_
" `" & fixQuotes( newusername ) & "`, " &_
" `" & fixQuotes( newpassword ) & "`, " &_
" `" & fixQuotes( email ) & "`, " &_
" `" & fixQuotes( street ) & "`, " &_
" `" & fixQuotes( town ) & "`, " &_
" `" & fixQuotes( county ) & "`, " &_
" `" & fixQuotes( postcode ) & "`, " &_
" `" & cctype & "`, " &_
" `" & fixQuotes( ccnumber ) & "`, " &_
" `" & ccexpires & "`, " &_
" `" & fixQuotes( nccname ) & "`, " &_
")"

Con.Execute sqlString

============================================================

Any ideas please? Thanks in advance!



  Re: Insert data into Access Database  Troy Wolf at 00:33 on Friday, August 01, 2003
 

Here is what I suggest: Right after you build the SQL statement and before you execute it, place this code:

Response.Write(sql)
Response.End

Then open your databse in Access and copy and paste the SQL statement into a query window. Access will reformat your query and point out what is wrong with the statement.
Troy Wolf: site expert
Shiny Solutions


  Re: Insert data into Access Database  Troy Wolf at 00:35 on Friday, August 01, 2003
 

Oh, and briefly looking at your SQL statement....you need to remove the comma that you have right before the closing ")". That may be your only problem.
Troy Wolf: site expert
Shiny Solutions


  Re: Insert data into Access Database  Archive Import (Joe) at 12:05 on Friday, August 01, 2003
 

Thanks for the reply. I eventually noticed that I had the extra comma at the end and managed to fix it. :D

But thanks for letting me know about:

"Then open your databse in Access and copy and paste the SQL statement into a query window. Access will reformat your query and point out what is wrong with the statement."

I didn`t know that. Thanks again!!

  Re: Insert data into Access Database  Archive Import (Joe) at 12:09 on Friday, August 01, 2003
 

I also made a mistake with the ` which should have all been `. Don`t know why I did that, heehee. :D

  Re: Insert data into Access Database  cheater_rh at 08:52 on Friday, September 26, 2003
 

maybe it's because the '. i got that problem few months ago and i tried to replace ' with chr(39) and i think it solved my problem. i hope this can help

  Re: Insert data into Access Database  cheater_rh at 08:56 on Friday, September 26, 2003
 

oops sorry, i mean replace it with chr(34) -.-'

  Re: Insert data into Access Database  asasamy at 02:49 on Monday, October 06, 2003
 

Hi there,
please check your inserting field, on the table design view, whether UNICODE COMPRESION is set to True , if so, just remove that and try to insert...

Will it help you ...as helped me..

Regards,
aS

  Re: Insert data into Access Database  prash at 22:36 on Wednesday, January 07, 2004
 

hello there,
i saw that many people are having with the same statement, i am having the same, but i dont have any of the above mentioned error in syntax or suggested solutions.

here is my code, if anyone can take a look, please email me a suggested solution.

is this something to do with the read/write security settings on the database that i am using, if it is, how do i fix it.

thank you

<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("newteam.mdb")
MyConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("newteam.mdb") & ";" & _
"Persist Security Info=False")

'"Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
set username = Request.Form("username")
set password = Request.Form("password")
SQL = "Insert into Passwords(Username,Password) Values ('" & Username & "','" & Password & "')"
MyConn.Execute(SQL)
%>
<HTML>

<BODY>
<%
response.write(username & " " & password)
%>


</BODY>
</HTML>








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005