如何在不将数据输入自动编号列的情况下将数据插入 MS Access table?

How to insert data into MS Access table without entering data into the AutoNumber column?

我正在使用 Microsoft Access 2016 开发一个 ASP.NET WebForm,我想在其中将数据输入 tbl_users table。我有以下服务器端代码:

connectionString = GetConnString();
string insertQuery = "insert into tbl_users (fullName, emailID, password) values(?, ?, ?)";
using (OleDbConnection con = new OleDbConnection(connectionString))
{
    con.Open();
    using (OleDbCommand insertCommand = new OleDbCommand(insertQuery, con))
    {
        insertCommand.CommandType = CommandType.Text;
        insertCommand.Parameters.AddWithValue("fullName", TextBoxFullName.Text);
        insertCommand.Parameters.AddWithValue("emailID", TextBoxEmailID.Text);
        insertCommand.Parameters.AddWithValue("password", TextBoxPassword.Text);        
        insertCommand.ExecuteNonQuery();
        con.Close();
    }
}

table 模式如下:

tbl_users(userID(AutoNumber), fullName(LongText), emailID(LongText), password(LongText))

当我 运行 代码时,出现以下错误:

System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement

我哪里错了?

password 是 Access SQL 中的关键字,因此需要用括号括起来。添加方括号 ([password]),您的查询将 运行 正常。

最终结果:

string insertQuery = "insert into tbl_users (fullName, emailID, [password]) values(?, ?, ?)";