Syntax error in INSERT INTO statement

S

Saber

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
 
N

Norman Yuan

If the code you showed here is directly copied from the source code, then
there are at least two obvious errors: no spaces after "myTable" and
"Values". Or are they just typos when you post?
 
B

Bob Lehmann

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
 
S

Saber

Thanks Bob,
You're right, "text" and "type" caused the error.
and about myTable, lol! it is because I just had one table and it looks like
better than Table1, but anyhow, now I've 4 tables and renamed myTable to
tblPosts! for your sake ;)

wait for next questions in next days!
 
S

Saber

Thanks Norman,
certainly I copied the code.
but the line has broken and the space disappeared, it is ok in source code.
 
J

Jo Inferis

Norman said:
If the code you showed here is directly copied from the source code,
then there are at least two obvious errors: no spaces after "myTable"
and "Values". Or are they just typos when you post?

Having no spaces there *isn't* a syntax error...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top