使用此代码,我正在执行更新...但是每当我使用现有数据进行更新时,都会显示“记录已更新”...这我不想要...代表这个我希望无法更新记录,因为数据已经存在。 ..所以我该怎么做..帮助..
protected void Button2_Click(object sender, EventArgs e)//Update
{
if (TexBo_num.Text == "" && TexBo_num.Text != "contact_no" )
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('contact number not be empty');", true);
}
else if(TxtBox_name.Text=="name" && TexBo_add.Text=="address" && TexBo_num.Text=="contact_no")
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('can't update the same record');", true);
}else
{
SqlConnection con = new SqlConnection(@"Data Source=SYSTEM2\SQLEXPRESS;Initial Catalog=amresh;Integrated Security=True");
SqlCommand cmd = new SqlCommand("UPDATE detail SET name='" + TxtBox_name.Text + "',address='" + TexBo_add.Text + "',contact_no='" + TexBo_num.Text + "' WHERE contact_no='" + TexBo_num.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('record updated');", true);
con.Close();
}
}