473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Syntax error in INSERT INTO statement

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,Ca t3,Cat4,Cat5)
Values(@title,@text,@type,@date,@authorid,@Cat1,@C at2,@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
Nov 18 '05 #1
5 1463
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?

"Saber" <saber[--AT--]maghalat.com> wrote in message
news:eP**************@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,Ca t3,Cat4,Cat5)
Values(@title,@text,@type,@date,@authorid,@Cat1,@C at2,@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

Nov 18 '05 #2
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:eP**************@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,Ca t3,Cat4,Cat5)
Values(@title,@text,@type,@date,@authorid,@Cat1,@C at2,@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

Nov 18 '05 #3
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!

"Bob Lehmann" <no****@dontbotherme.zzz> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #4
Thanks Norman,
certainly I copied the code.
but the line has broken and the space disappeared, it is ok in source code.

"Norman Yuan" <no****@nowhere.no> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?

Nov 18 '05 #5
Norman Yuan wrote:
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...

--
jo inferis
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
3
by: jinhy82 | last post by:
Hi! I am currently creating a Registration form which contained: UserID Password, FirstName and LastName. These details would be inserted into Ms Access when I click submi button. But I...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
1
by: vasanth chandrasekaran | last post by:
The error is :Syntax error in INSERT INTO statement. This is my code: try { DataSet ds1; OleDbConnection ConnSql; OleDbConnection...
9
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
0
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.