using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 作业
{
public partial class frmModifyPwd : Form
{
public frmModifyPwd()
{
InitializeComponent();
} private void btnModify_Click(object sender, EventArgs e)
{
if (txtNewPwd.Text.Trim() == txtNewPassWordAgain.Text.Trim())
{
string connString = "Data source=fjh.\\sqlexpress;Initial Catalog=zuoye;User ID=sa;Password=fjh "; SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sqlCheckPwd = "select count( *) from UserInfo where UserName='admin'and UserPwd='" + txtOldPwd.Text.Trim() + "'";
SqlCommand cmdCheckPwd = new SqlCommand(sqlCheckPwd, conn);
int j=(int)cmdCheckPwd.ExecuteScalar();
if (j == 1)
{
string sql = "updata UserInfo set UserPwd='" + txtNewPassWordAgain.Text.Trim() + "'where UserName='admin'";
SqlCommand cmd = new SqlCommand(sql,conn);
int i = cmd.ExecuteNonQuery(); //---------此处提示等号处有语法错误,哪错误啊?谢了
if (i == 1)
{
MessageBox.Show("密码修改成功");
}
else
{
MessageBox.Show("密码修改失败");
}
}
else
{
MessageBox.Show("旧密码不正确");
}
conn.Close();
}
else
{
MessageBox.Show("两次密码不一致");
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 作业
{
public partial class frmModifyPwd : Form
{
public frmModifyPwd()
{
InitializeComponent();
} private void btnModify_Click(object sender, EventArgs e)
{
if (txtNewPwd.Text.Trim() == txtNewPassWordAgain.Text.Trim())
{
string connString = "Data source=fjh.\\sqlexpress;Initial Catalog=zuoye;User ID=sa;Password=fjh "; SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sqlCheckPwd = "select count( *) from UserInfo where UserName='admin'and UserPwd='" + txtOldPwd.Text.Trim() + "'";
SqlCommand cmdCheckPwd = new SqlCommand(sqlCheckPwd, conn);
int j=(int)cmdCheckPwd.ExecuteScalar();
if (j == 1)
{
string sql = "updata UserInfo set UserPwd='" + txtNewPassWordAgain.Text.Trim() + "'where UserName='admin'";
SqlCommand cmd = new SqlCommand(sql,conn);
int i = cmd.ExecuteNonQuery(); //---------此处提示等号处有语法错误,哪错误啊?谢了
if (i == 1)
{
MessageBox.Show("密码修改成功");
}
else
{
MessageBox.Show("密码修改失败");
}
}
else
{
MessageBox.Show("旧密码不正确");
}
conn.Close();
}
else
{
MessageBox.Show("两次密码不一致");
}
}
}
}
中应该是update