根据我的代码“您的密码已成功更改!恭喜!” 即使更新不起作用,也会弹出消息。如果没有进行更新,我该如何给出错误消息(我的更新语句中似乎也有错误..)。实际上我无法想象如何在这里使用 if 语句..
protected void Button1_Click(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection("server=localhost; database=e-learningsystem; uid=root; password=123;port=3307;");
connection.Open();
try
{
MySqlCommand cmd1 = new MySqlCommand("UPDATE student Set Password= '" + TextBox3.Text + "' WHERE UserName='" + TextBox1.Text + "' AND Password='"+TextBox2.Text+"'", connection);
cmd1.ExecuteNonQuery();
Response.Write(@"<script language='javascript'>alert('Your Password Has Been Changed successfully!, Congratulations!')</script>");
connection.Close();
}
catch (Exception ex)
{
Response.Write(@"<script language='javascript'>alert(ex.Message)</script>");
}
}