SQL related question

Results 1 to 4 of 4

Thread: SQL related question

  1. #1
    Join Date
    Dec 1969

    Default SQL related question

    I&#039;m trying to write a simple ASP/VBScript sub-routine that adds data to an MS Access table via the "INSERT INTO" statement. I&#039;m getting the following error msg: <BR><BR>"error &#039;80040e14&#039; Syntax error in INSERT INTO statement" <BR><BR>which refers to the following portion of my embedded sql:<BR><BR> sql = "Insert Into names ("<BR> sql = sql & "Id,"<BR> sql = sql & "F_name,"<BR> sql = sql & "L_name"<BR> sql = sql & ") "<BR> sql = sql & "Values ("<BR> sql = sql & ","<BR> <BR> sql = sql & "&#039;" & SqlQuote(F_name) & "&#039;,"<BR> sql = sql & "&#039;" & SqlQuote(L_name) & "&#039;"<BR> sql = sql & ");"<BR><BR>The "Id" field is an AutoNumber datatype... I have a feeling this is the root of the problem. My sql is rusty, so I&#039;ve kind of forgotten the syntax of how to deal with Autonumber types in terms of inserting, updating etc. <BR><BR>Please help! <BR><BR>Akshay

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL related question

    sql = "Insert Into names (" <BR>sql = sql & "F_name," <BR>sql = sql & "L_name" <BR>sql = sql & ") " <BR>sql = sql & "Values (" <BR>sql = sql & "," <BR><BR>sql = sql & "&#039;" & SqlQuote(F_name) & "&#039;," <BR>sql = sql & "&#039;" & SqlQuote(L_name) & "&#039;" <BR>sql = sql & ");" <BR><BR>uxt ignore Id in your SQL, it will update automatically<BR><BR>HTH<BR>Dave

  3. #3
    Conrad Guest

    Default RE: SQL related question

    You are forgetting the apostrophe.<BR>Try:<BR><BR>strSql = ""<BR>strSql = strSQl & "INSERT INTO names(&#039;Id&#039;,&#039;F_name&#039;,&#039;L_na me&#039;)"<BR>strSql = strSQl & "VALUES(&#039;&#039;,&#039;" & SqlQuote(F_name) & "&#039;,&#039;" & SqlQuote(L_name) & "&#039;)"<BR><BR><BR>You are encasing your string in quots but are forgetting the apostophe - &#039;.<BR><BR>When you are having errors in creating a dynamic string put:<BR>On Error Resume Next<BR>At the top of your page and Response.Write you SQL statement, you will clearly see the error.<BR><BR>Don&#039;t forget to remove the On Error Resume Next after you have seen the SQL string printed out.<BR><BR>Conrad

  4. #4
    Joel N Guest

    Default RE: SQL related question

    Don&#039;t put quotes around the field names....<BR>sql = "Insert Into names (Id,F_name,L_name) Values (" & SqlQuote(F_name) & "," & SqlQuote(L_name) & ");"<BR><BR><BR>Also, from the looks of it someone has written a function called SqlQuote that fixes up the strings to include single quotes around them. It probably also escapes single quotes into a set of two single quotes so (as Bill W. is fond of pointing out) names like "O&#039;Brien" don&#039;t blow up your insert. SO...you may need to put the single quotes back in around the calls to SqlQuote() but look at the code it&#039;s running before you do.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts