将值传递给mdb时update语句中的语法错误

时间:2015-03-26 07:04:40

标签: c#

请帮助,在update语句中获取语法错误。 当我尝试更新数据库中的值(msaccess)

时会发生这种情况
try
        {

            DialogResult dr = MessageBox.Show("Are you sure you want to update?", "Details Updation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.No)
            {
                return;
            }
            else
            {                    
                OleDbConnection oleDbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=users.mdb;Persist Security Info=False");
                OleDbCommand update = new OleDbCommand("UPDATE users SET user = '"+textBox2.Text+"' where code = 1", oleDbConnection);
                oleDbConnection.Open();
                update.ExecuteNonQuery();
                oleDbConnection.Close();

                MessageBox.Show("User name updated successfully", "Update Username", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
catch (SystemException se)
{
    MessageBox.Show(se.Message);
}
finally
{

}

0 个答案:

没有答案