protected void btnupdate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString); if (txtjnamei.Text != "" && txtjagei.Text != "" && ddjsexi.Text != "" && ddjrecordi.Text != "" && ddjworkyeari.Text != "" && txtjphonei.Text != "" && txtjemaili.Text != "" && ddjobsi.Text != "")
{
if (HttpContext.Current.Session["CheckCode"].ToString().Equals(this.txtjverifyi.Text.ToString().Trim()))
{
try
{
con.Open();
string updatesql = "Update jobperson set jusername='" + txtjusernamei.Text + "',jname='" + txtjnamei.Text + "',jage='" + txtjagei.Text + "',jsex='" + ddjsexi.Text + "',jworkyear='" + ddjworkyeari.Text + "',jemail='" + txtjemaili.Text + "',jrecord='" + ddjrecordi.Text + "',jphone='" + txtjphonei.Text + "',jobs='" + ddjobsi.Text + "',jdetailed='" + txtjdetailedi.Text + "' where jID='" + Label4i.Text + "'";
SqlCommand cmd = new SqlCommand(updatesql, con);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i != 1)
{
Label5i.Text = "<script>alert('修改成功!')</script>";
}
else
{
Label5i.Text = "<script>alert('失败!')</script>";
}
}
catch (SqlException ex)
{
throw ex;
}
finally
{
con.Close();
}
}
else
{
Label5i.Text = "<script>alert('验证码不正确')</script>";
}
}
else
{
Label5i.Text = "<script>alert('请填完整的信息')</script>";
}
}
{
SqlConnection con = new SqlConnection(connectionString); if (txtjnamei.Text != "" && txtjagei.Text != "" && ddjsexi.Text != "" && ddjrecordi.Text != "" && ddjworkyeari.Text != "" && txtjphonei.Text != "" && txtjemaili.Text != "" && ddjobsi.Text != "")
{
if (HttpContext.Current.Session["CheckCode"].ToString().Equals(this.txtjverifyi.Text.ToString().Trim()))
{
try
{
con.Open();
string updatesql = "Update jobperson set jusername='" + txtjusernamei.Text + "',jname='" + txtjnamei.Text + "',jage='" + txtjagei.Text + "',jsex='" + ddjsexi.Text + "',jworkyear='" + ddjworkyeari.Text + "',jemail='" + txtjemaili.Text + "',jrecord='" + ddjrecordi.Text + "',jphone='" + txtjphonei.Text + "',jobs='" + ddjobsi.Text + "',jdetailed='" + txtjdetailedi.Text + "' where jID='" + Label4i.Text + "'";
SqlCommand cmd = new SqlCommand(updatesql, con);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i != 1)
{
Label5i.Text = "<script>alert('修改成功!')</script>";
}
else
{
Label5i.Text = "<script>alert('失败!')</script>";
}
}
catch (SqlException ex)
{
throw ex;
}
finally
{
con.Close();
}
}
else
{
Label5i.Text = "<script>alert('验证码不正确')</script>";
}
}
else
{
Label5i.Text = "<script>alert('请填完整的信息')</script>";
}
}
{
Label5i.Text = " <script>alert('修改成功!') </script>";
} ??????方法ExecuteNonQuery()是返回语句影响的行数,你这里的判断条件有问题吧?
if(i>0)
{
成功
}
else
{
失败
}
那就用Response.Write("<script>alert('修改成功')</script>");
这里有问题
就像2楼说的,if 语句里的判断改成(i>0)试试看吧。
{
Label5i.Text = " <script>alert('修改成功!') </script>";
}
else
{
Label5i.Text = " <script>alert('失败!') </script>";
}
如果你的i是0的话也是成功的,其实是失败的。