我正在使用Microsoft Access 2016并开发一个ASP.NET WebForm,我希望将数据输入tbl_users
表。我有以下服务器端代码:
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();
}
}
表格模式如下:
tbl_users(userID(AutoNumber), fullName(LongText), emailID(LongText), password(LongText))
当我运行代码时,出现以下错误:
System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement
我哪里错了?
答案 0 :(得分:1)
password
是Access SQL中的关键字,因此需要加括号。添加括号([password]
),您的查询就可以正常运行。
最终结果:
string insertQuery = "insert into tbl_users (fullName, emailID, [password]) values(?, ?, ?)";