Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Syntax error in INSERT INTO statement

Reply
Thread Tools

Syntax error in INSERT INTO statement

 
 
Saber
Guest
Posts: n/a
 
      07-18-2004
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


 
Reply With Quote
 
 
 
 
Norman Yuan
Guest
Posts: n/a
 
      07-18-2004
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:...
> 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
>
>



 
Reply With Quote
 
 
 
 
Bob Lehmann
Guest
Posts: n/a
 
      07-18-2004
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:...
> 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
>
>



 
Reply With Quote
 
Saber
Guest
Posts: n/a
 
      07-18-2004
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" <> wrote in message
news:...
> 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



 
Reply With Quote
 
Saber
Guest
Posts: n/a
 
      07-18-2004
Thanks Norman,
certainly I copied the code.
but the line has broken and the space disappeared, it is ok in source code.

"Norman Yuan" <> wrote in message
news:%23q4$...
> 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?



 
Reply With Quote
 
Jo Inferis
Guest
Posts: n/a
 
      07-20-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL syntax error in INSERT INTO statement Nathan Sokalski ASP .Net 5 09-03-2010 02:12 AM
-2147217900:Syntax error in INSERT INTO statement. solomon_13000 ASP General 1 10-02-2006 07:08 PM
Syntax error in INSERT INTO statement Gérard Leclercq ASP General 6 02-02-2005 03:11 PM
password field: Syntax error in INSERT INTO statement. Neil Zanella ASP .Net 3 01-25-2005 02:49 AM
adapter update problem Syntax error in INSERT INTO statement. compuglobalhypermeganetz0r ASP .Net 0 12-08-2003 05:03 AM



Advertisments