MySqlConnection myConnection1 = new MySqlConnection(login_Connection_String);
string myUpdateQuery = "UPDATE tb_user SET tb_user.Password = " + textBox_new_pwd.Text.ToString() + " WHERE tb_user.User_ID = '" + textBox_login_name.Text.ToString() + "'" ;
// string myDelQuery = "DELETE FROM tb_user WHERE tb_user.User_ID = " + textBox_login_name.Text;
// string myInsQuery = "INSERT (" + textBox_new_pwd.Text +","+ textBox_login_name.Text + ") into tb_user";
MySqlCommand myUpdateCommand = new MySqlCommand(myUpdateQuery, myConnection1);
//修改tb_user 中对应User_ID的密码
myUpdateCommand.Connection.Open();
myUpdateCommand.ExecuteNonQuery();
myUpdateCommand.Connection.Close();
MessageBox.Show("修改密码成功!");
string myUpdateQuery = "UPDATE tb_user SET tb_user.Password = " + textBox_new_pwd.Text.ToString() + " WHERE tb_user.User_ID = '" + textBox_login_name.Text.ToString() + "'" ;
// string myDelQuery = "DELETE FROM tb_user WHERE tb_user.User_ID = " + textBox_login_name.Text;
// string myInsQuery = "INSERT (" + textBox_new_pwd.Text +","+ textBox_login_name.Text + ") into tb_user";
MySqlCommand myUpdateCommand = new MySqlCommand(myUpdateQuery, myConnection1);
//修改tb_user 中对应User_ID的密码
myUpdateCommand.Connection.Open();
myUpdateCommand.ExecuteNonQuery();
myUpdateCommand.Connection.Close();
MessageBox.Show("修改密码成功!");
本文介绍了一个使用 C# 连接 MySQL 数据库并更新用户密码的示例。通过 MySqlCommand 对象执行 SQL 更新语句,实现对 tb_user 表中指定 User_ID 的密码进行修改。
633

被折叠的 条评论
为什么被折叠?



