问题描述
- C#连接Acess做密码修改的程序,程序提示UPDATE语句错误。各位帮个忙
-
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace LoginApp { public partial class frmChange : Form { public frmChange() { InitializeComponent(); } private void btnOK_Click(object sender, EventArgs e) { if (txtOldPwd .Text ==""||txtNewPwd .Text ==""||txtNewPwd2 .Text =="") { if (MessageBox.Show(" 您输入的信息不完整!,是否关闭窗口", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); } } else if (txtNewPwd.Text !=txtNewPwd2 .Text ) { if (MessageBox.Show(" 您的新密码输入不一致!,是否关闭窗口", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); } } else if (txtOldPwd .Text !="") { string connString = Properties.Settings.Default.connString; OleDbConnection connection = new OleDbConnection(connString); string sq1 = "select password from users where username='admin'"; OleDbDataAdapter OleDbDataAdapte1 = new OleDbDataAdapter(sq1, connString); DataSet dt1 = new DataSet(); OleDbDataAdapte1.Fill(dt1, "users"); string sq2 = txtOldPwd.Text; string sq3 = (string)dt1.Tables["users"].Rows[0]["password"]; if (sq2 .Equals (sq3 .Trim ()) && txtNewPwd .Text ==txtNewPwd2 .Text ) { string constr1 = Properties.Settings.Default.connString; string sq4 = "UPDATE users set password ='" + txtNewPwd.Text.Trim() + "' where username='admin'"; OleDbConnection conn = new OleDbConnection(connString); conn.Open(); OleDbCommand cd = new OleDbCommand(sq4,conn ); OleDbDataReader sr = cd.ExecuteReader(); MessageBox.Show("密码已修改成功 ", "提醒"); } } } } }
//程序有三个textbox 分别叫txtOldPwd用来写原密码还有叫txtNewpwd用来写新密码还有个叫txtNewpwd2用来判断新密码是否一致。代码写好了。程序就报错UPDATE语句错误
时间: 2024-10-30 17:22:04