Syntax error in INSERT statement into MS Access

末鹿安然 提交于 2019-12-02 01:19:02

Seems like Password is a reserved keyword in OLE DB Provider. Use it with square brackets like [Password]. But as a best practise, change it to non-reserved word.

And OleDbCommand doesn't support named parameters.

From documentation;

The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:

SELECT * FROM Customers WHERE CustomerID = ?

Therefore, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

In documentation it says ? must be used but actually, it is not. Named parameters do work, but the names are irrelevant; it's still the position of the parameters in the CommandText and the order in which they are added that matters.

And don't use AddWithValue anymore. It may generate unexpected results sometimes. Use .Add() method or it's overloads.

Read: Can we stop using AddWithValue() already?

Finally, you don't need to close your connection manually with con.Close() in your finally block because using statement automatically handle it.

By the way, I have to say, accessLevelIdD column sounds like a numeric type from it's name since it ends with ID. If it is (or should or not), you need to pass value as 2 not '2'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!