Results 1 to 9 of 9

Thread: Syntax Error in INSERT INTO statement

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    54

    Syntax Error in INSERT INTO statement

    Help this is not new and I know the problem but cant fix it. I am rewriting a program in vb.net and the original Access database has a field name call 'Day' (Reserved Word)

    I want to keep the name as I cannot change the data structure not practical(too many copies about)

    I am using dataset and databinded controls. The following is snippets from the source code.

    VB Code:
    1. Dim stSQL As String = "Select ID,[Day],PilotID Where PilotID=" & PilotID
    2.  
    3.         da = New OleDbDataAdapter(stSQL, pConnection)
    4.         ds.Clear()
    5.  
    6.         Try
    7.             da.Fill(ds, "tblLogbook")
    8.         Catch ex As Exception
    9.  
    10.         End Try

    My controls are binded as such:

    VB Code:
    1. txtPilotID.DataBindings.Add("Value", dbLogbook.ds, "tblLogbook.PilotID")
    2.         txtDay.DataBindings.Add("Value", dbLogbook.ds, "tblLogbook.Day")

    my insertcommand is as follows
    VB Code:
    1. cmdInsert.Connection = FTLDb ' FTLDb is a declared connection object
    2.         cmdInsert.CommandText = "Insert Into tblLogbook (PIlotID,[Day]) Values (@PIlotID,@Day)"
    3.  
    4.         cmdInsert.Parameters.Add(New OleDbParameter("@PIlotID", "PIlotID"))
    5.         cmdInsert.Parameters.Add(New OleDbParameter("@Day", "[Day]"))
    6.         da.InsertCommand = cmdInsert

    When I call
    VB Code:
    1. da.Update(ds, "tblLogbook")

    I get the error message 'Syntax Error in INSERT INTO statement'
    I know the problem is Day because if I change the name in the database to something else, it works. I am looking for a resolution without changing the datastructure. I know I have to use square brackets but where?
    Last edited by 99pshop; Oct 21st, 2005 at 11:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width