I am trying to perform an INSERT query into an access database with VB.NET, and it keeps complaining that I have a syntax error. I can't seem to figure it out though. If I run it in Access itself, it works.
To give you a glimpse of what is happening, here is some debugging code :
Dim params(6) As OleDb.OleDbParameter
params(0) = New OleDb.OleDbParameter("@matchNumber", Integer.Parse(recMatchNumber))
params(1) = New OleDb.OleDbParameter("@teamNumber", Integer.Parse(recTeamNumber))
params(2) = New OleDb.OleDbParameter("@action", recAction)
params(3) = New OleDb.OleDbParameter("@object", recObject)
params(4) = New OleDb.OleDbParameter("@level", recLevel)
params(5) = New OleDb.OleDbParameter("@location", recLocation)
params(6) = New OleDb.OleDbParameter("@time", recTime)
For Each param As OleDb.OleDbParameter In params
Console.WriteLine(command.CommandText)
Console.WriteLine(param.ParameterName)
Console.WriteLine(param.Value)
command.Parameters.Add(param)
Next
And here is the result :
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@matchNumber
1
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@teamNumber
50
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@action
Move
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@object
Robot
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@level
0
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@location
Zone
INSERT INTO matchData( matchNumber, teamNumber, action, object, [level], location, [time]) VALUES(@matchNumber,@teamNumber,@action,@object,@level,@location,@time)
@time
Auto
The error is Syntax error in INSERT INTO statement.
Thanks.
objectis a keyword. Put it in brackets. If it's not too late, I would change that field name to something more descriptive.actionandobjectare both reserved words