I'm not sure where this error can be coming from.
I'm using VB.NET to insert data into MS Access 2016. I'm able to execute other SQL queries no problem, but this one returns the Syntax error in INSERT INTO statement error:
sql = "INSERT INTO Sense_Translation (SenseFK, LanguageCode, Translation) VALUES (?, ?, ?)"
cmd = New OleDbCommand(sql, myConnection)
cmd.Parameters.Add(New OleDbParameter("SenseFK", senseID))
cmd.Parameters.Add(New OleDbParameter("LanguageCode", lcodeID))
cmd.Parameters.Add(New OleDbParameter("Translation", tr.Translation))
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
I've checked and double checked that the table name in Access and VB.NET match, that the parameters match, and that the parameters are in the correct order corresponding to the Access table, both in the SQL statement, and in the Parameters.Add statements (I'm not even sure if the latter matters, I just do it just in case.)
I've also checked that the types being passed to the parameters match - senseID is a number, lcodeID is a number, and tr.Translation is a string, which matches the table. Although if it was a type mismatch I expect the error would be different anyway.
Just for comparison, when I executed the code below, this did not return an error:
sql = "INSERT INTO Sense (EntryFK, SenseInformation) VALUES (?, ?)"
cmd = New OleDbCommand(sql, myConnection)
cmd.Parameters.Add(New OleDbParameter("EntryFK", entryID))
cmd.Parameters.Add(New OleDbParameter("SenseInformation", ss.SenseInformation))
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
And as far as I can tell there is no difference between the two SQL statements except for the number of parameters, which shouldn't matter.
Is there something kickself-obvious that I've missed here, or is the problem likely to be more insidious?