Syntax error in INSERT INTO statement

Discussion in 'ASP .Net' started by Saber, Jul 18, 2004.

  1. Saber

    Saber Guest

    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
     
    Saber, Jul 18, 2004
    #1
    1. Advertising

  2. Saber

    Norman Yuan Guest

    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,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
    >
    >
     
    Norman Yuan, Jul 18, 2004
    #2
    1. Advertising

  3. Saber

    Bob Lehmann Guest

    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,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
    >
    >
     
    Bob Lehmann, Jul 18, 2004
    #3
  4. Saber

    Saber Guest

    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
     
    Saber, Jul 18, 2004
    #4
  5. Saber

    Saber Guest

    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?
     
    Saber, Jul 18, 2004
    #5
  6. Saber

    Jo Inferis Guest

    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
     
    Jo Inferis, Jul 20, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. compuglobalhypermeganetz0r

    adapter update problem Syntax error in INSERT INTO statement.

    compuglobalhypermeganetz0r, Dec 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    854
    compuglobalhypermeganetz0r
    Dec 8, 2003
  2. Neil Zanella
    Replies:
    3
    Views:
    681
    MWells
    Jan 25, 2005
  3. Nathan Sokalski

    SQL syntax error in INSERT INTO statement

    Nathan Sokalski, Jul 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    14,723
    ahmed_samir
    Sep 3, 2010
  4. Gérard Leclercq

    Syntax error in INSERT INTO statement

    Gérard Leclercq, Feb 1, 2005, in forum: ASP General
    Replies:
    6
    Views:
    230
    Bob Barrows [MVP]
    Feb 2, 2005
  5. solomon_13000

    -2147217900:Syntax error in INSERT INTO statement.

    solomon_13000, Oct 2, 2006, in forum: ASP General
    Replies:
    1
    Views:
    286
    Bob Barrows [MVP]
    Oct 2, 2006
Loading...

Share This Page