关于文本框为空
本文关键字:文本 于文本 | 更新日期: 2023-09-27 18:32:29
插入,更新和删除后,我想要我的文本。盒子空...那我该怎么做呢.????
protected void Button4_Click(object sender, EventArgs e) //delete
{
if (TexBo_num.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('contact_no is coumpulsary');", true);
}
else
{
SqlConnection con = new SqlConnection(@"Data Source=SYSTEM2'SQLEXPRESS;Initial Catalog=amresh;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("delete from detail where contact_no=" + TexBo_num.Text, con);
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('record deleted')", true);
con.Close();
}
}
问题不是很清楚,只需在执行 comman 后设置它的 Text 属性即可。
cmd.ExecuteNonQuery();
TexBo_num.Text = "";
请注意,您应该使用 sql 参数来防止 sql 注入攻击。
SqlCommand cmd = new SqlCommand("delete from detail where contact_no=@contactNo", con);
cmd.Parameters.AddWithValue("@contactNo", TexBo_num.Text);