Re: Syntax error in INSERT INTO statement

From: Bob Lehmann (nospam_at_dontbotherme.zzz)
Date: 07/18/04


Date: Sun, 18 Jul 2004 14:49:05 -0600

You have at least one reserved word in your query - date. "text" and "type"
are suspect also.
http://www.aspfaq.com/show.asp?id=2080

Change the column names, or enclose them in [] - [date].

myTable is an odd table name. Do you have some tables that are somebody
else's?

Bob Lehmann

"Saber" <saber[--AT--]maghalat.com> wrote in message
news:eP7Z4HQbEHA.1548@TK2MSFTNGP12.phx.gbl...
> I'm using a table named myTable in Access, but when I try it I get:
> Syntax error in INSERT INTO statement.
> in access db, the Cat1,Cat2,..,Cat5 are Yes/No and their format is
> True/False
> any idea?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> here is a piece of code:
>
> strSqlPost = "Insert into
> myTable(title,text,type,date,authorid,Cat1,Cat2,Cat3,Cat4,Cat5)
> Values(@title,@text,@type,@date,@authorid,@Cat1,@Cat2,@Cat3,@Cat4,@Cat5)"
> cmdSqlPost = New OleDbCommand(strSqlPost, conPost)
> cmdSqlPost.Parameters.Add("@title", txtTitle.Text)
> cmdSqlPost.Parameters.Add("@text", txtBody.Text)
> Select Case drpType.SelectedValue
> Case "weblog"
> cmdSqlPost.Parameters.Add("@type", 1) 'means weblog
> Case "news"
> cmdSqlPost.Parameters.Add("@type", 2) 'means news
> Case "article"
> cmdSqlPost.Parameters.Add("@type", 3) 'means article
> End Select
> cmdSqlPost.Parameters.Add("@date", Now.Date)
> cmdSqlPost.Parameters.Add("@authorid", 23)
> 'cmdSqlPost.Parameters.Add("@cat1", chkCats.Items(0).Selected)
> 'cmdSqlPost.Parameters.Add("@cat2", chkCats.Items(1).Selected)
> 'cmdSqlPost.Parameters.Add("@cat3", chkCats.Items(2).Selected)
> 'cmdSqlPost.Parameters.Add("@cat4", chkCats.Items(3).Selected)
> 'cmdSqlPost.Parameters.Add("@cat5", chkCats.Items(4).Selected)
> cmdSqlPost.Parameters.Add("@Cat1", False)
> cmdSqlPost.Parameters.Add("@Cat2", False)
> cmdSqlPost.Parameters.Add("@Cat3", True)
> cmdSqlPost.Parameters.Add("@Cat4", False)
> cmdSqlPost.Parameters.Add("@Cat5", False)
> Try
> ConnectDB(conPost)
> cmdSqlPost.ExecuteNonQuery()
> DisconnectDB(conPost)
> lblStatus.ForeColor = Drawing.Color.Green
> lblStatus.Text = "OK"
> Catch ex As Exception
> lblStatus.ForeColor = Drawing.Color.Red
> lblStatus.Text = ex.Message
> End Try
>
>



Relevant Pages

  • Re: Need help with Code Please!!!
    ... I believe Case is a reserved word. ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)
  • RE: Access 2007 syntax error
    ... I believe that you've hit on a reserved word problem. ... query using the query design window--I don't know how to program SQL. ... Parameters table that I want to use to specify criteria. ...
    (microsoft.public.access.queries)
  • Re: Date BETWEEN
    ... As Jerry mentioned, Date is a reserved word in Access, and should not be used ... so your query would look like: ... "Steve Wagner" wrote: ... square brackets around it like so: ...
    (microsoft.public.access.queries)
  • Odd and Even numbers
    ... I added a autonumber field to the table so now all the odd ... I intended to do a make table query selecting only the odd ... table with only business names, then do a make table query ...
    (microsoft.public.access.queries)
  • Re: Subtracting two sum fields on a seperate field on query
    ... Microsoft Access treats the word "Date" as a reserved word (along with many ... Another possibility is to take the difference in your first query (e.g. ... Field: Sum of Call Recvd ...
    (microsoft.public.access.gettingstarted)