Home All Groups Group Topic Archive Search About

INSERT SQL Error. What is wrong?

Author
30 Jun 2005 9:43 PM
Shapper
Hello,

I need to add a new record to an ACCESS database.

I get the error: Syntax error in INSERT INTO statement.

I have no idea what am I doing wrong. This is my code:

' Set Connection
  Dim connectionString As String = AppSettings("connectionString")
  Dim dbConnection As IDbConnection = New
OleDbConnection(connectionString)

' Set Query
  Dim queryString As String = "INSERT INTO t_news (title_pt-PT,
title_en-GB, text_pt-PT, text_en-GB, publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB,
@publication_date)"

  Dim dbCommand As IDbCommand = New OleDbCommand
  dbCommand.CommandText = queryString
  dbCommand.Connection = dbConnection

' Add Parameters
  With dbCommand.Parameters
    .Add(New OleDbParameter("@title_pt-PT", "sample"))
    .Add(New OleDbParameter("@title_en-GB", "sample"))
    .Add(New OleDbParameter("@text_pt-PT", "sample"))
    .Add(New OleDbParameter("@text_en-GB", "sample"))
    .Add(New OleDbParameter("@publication_date", DateTime.Now))
  End With

' Insert Record
  dbConnection.Open
  Try
    dbCommand.ExecuteNonQuery
  Finally
    dbConnection.Close
  End Try

Can someone tell me what is wrong?

Thanks,
Miguel

Author
1 Jul 2005 6:55 AM
Tibor Karaszi
You should post this to an Access group. I have a feeling that the Access driver doesn't like the
@parm notation.

Show quote
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:uWePCzbfFHA.3960@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I need to add a new record to an ACCESS database.
>
> I get the error: Syntax error in INSERT INTO statement.
>
> I have no idea what am I doing wrong. This is my code:
>
> ' Set Connection
>  Dim connectionString As String = AppSettings("connectionString")
>  Dim dbConnection As IDbConnection = New OleDbConnection(connectionString)
>
> ' Set Query
>  Dim queryString As String = "INSERT INTO t_news (title_pt-PT, title_en-GB, text_pt-PT,
> text_en-GB, publication_date) VALUES (@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB,
> @publication_date)"
>
>  Dim dbCommand As IDbCommand = New OleDbCommand
>  dbCommand.CommandText = queryString
>  dbCommand.Connection = dbConnection
>
> ' Add Parameters
>  With dbCommand.Parameters
>    .Add(New OleDbParameter("@title_pt-PT", "sample"))
>    .Add(New OleDbParameter("@title_en-GB", "sample"))
>    .Add(New OleDbParameter("@text_pt-PT", "sample"))
>    .Add(New OleDbParameter("@text_en-GB", "sample"))
>    .Add(New OleDbParameter("@publication_date", DateTime.Now))
>  End With
>
> ' Insert Record
>  dbConnection.Open
>  Try
>    dbCommand.ExecuteNonQuery
>  Finally
>    dbConnection.Close
>  End Try
>
> Can someone tell me what is wrong?
>
> Thanks,
> Miguel
>

AddThis Social Bookmark Button