Incorrect Syntax in INSERT INTO STATEMENT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gilesy
    New Member
    • Sep 2009
    • 3

    #1

    Incorrect Syntax in INSERT INTO STATEMENT

    Hi, I have a ploblem with an insert statement using an access database, I have the same code with a sql database which works but it doesn't seem to work on access. Could someone please help.
    [code=VBNET]
    For i = 0 To dg.Rows.Count - 1
    Main.Command.Co mmandText = "INSERT INTO Diary (Date1, Time, Appointment) VALUES (?, ?, ?)"
    Dim param1 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Date1", dg(1, i).Value)
    Dim param2 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Time", dg(2, i).Value)
    Dim param3 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Appointment ", dg(3, i).Value)

    Main.Command.Pa rameters.Add(pa ram1)
    Main.Command.Pa rameters.Add(pa ram2)
    Main.Command.Pa rameters.Add(pa ram3)

    Try
    Main.Command.Ex ecuteNonQuery()
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try
    Main.Command.Pa rameters.Clear( )
    [/code]
    i get "syntax error in INSERT INTO Statement" i've tried writing the values directly into the command text and that gives me the same error. Am I missing something totally obvious here?

    Thanks in advance.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Access uses slightly different forms of SQL, have you verified that your SQL code will work in access before trying to use it in .NET?

    Is this "(?, ?, ?)" a valid way to add parameters?

    Comment

    Working...