asp.net 为啥我的alert在catch里面捕捉到数据库约束错误时 就没反映 其他的错误有反映
try
{
age =int.Parse(TextBox2.Text);
cmd.CommandText = "Update StuInfo Set StuName='" + name + "',StuAge=" + age + ",StuSex='" + sex + "',StuPhone='" + phone + "',Pwd='" + pwd + "' Where StuNum='1'";
cmd.ExecuteNonQuery();
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('修改成功!请牢记密码!');</script>");
}
catch (Exception ex)
{
//Response.Write("<script defer='defer'>alert('" + ex.Message + "');</script>");
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message","<script language='javascript' defer>alert('"+ex.Message.ToString()+"');</script>");
}
finally
{
SqlCon.Close();
cmd = null;
}
当ex.message为违反数据库约束时,页面没有弹出提示框,而当try里面的 转化格式错误时会有提示框弹出
60了 求关注!!!!