首先我知道密码是一种保留类型的Access数据库。但我读过一篇文章,你可以像那样输入 [password] 并且它会起作用。但它不起作用。我已经尝试了很多方法,但仍然希望有人能有所帮助。
OleDbCommand cmd = new OleDbCommand();
try
{
String query = "update [Employe] set [UserName] ='" + txtNewUser.Text +"', [Password] ='"+ txtNewPass.Text + "', [Authorization] ='" + nudAuthorizationLvl.Value + "', where [Id] = '" + int.Parse(txtExistingId.Text);
cmd.CommandText = query;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
System.Windows.Forms.MessageBox.Show("Info Updated!!!");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
finally
{
conn.Close();
}
最佳答案
我相信您在 where
子句之前有一个额外的逗号,在 ID 之前有一个额外的引号。
此外,始终使用参数,以避免 Sql 注入(inject)攻击:
conn.Open();
cmd.CommandText = "update [Employe] set [UserName] =@userName, [Password] =@password, [Authorization] =@authorization where [Id] = @id";
cmd.Connection = conn;
cmd.Parameters.AddRange(new OleDbParameter[]
{
new OleDbParameter("@userName", txtNewUser.Text),
new OleDbParameter("@password", txtNewPass.Text),
new OleDbParameter("@authorization", nudAuthorizationLvl.Value),
new OleDbParameter("@id", int.Parse(txtExistingId.Text))
});
cmd.ExecuteNonQuery();
关于c# - update into 语句中 Access 数据库语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29873436/