在这段代码中,我想更新该contact_no
字段但它不起作用,并且我想在更新、删除或插入后设置刷新。
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
{
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();
}
}