-1

插入、更新和删除后,我希望我的 TEXT.BOX 为空……那我该怎么做……????

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();
    }
}
4

1 回答 1

0

问题不是很清楚,执行命令后设置它的 Text 属性即可。

cmd.ExecuteNonQuery();
TexBo_num.Text = "";

请注意,您应该使用 sql-parameters 来防止 sql-injection 攻击

SqlCommand cmd = new SqlCommand("delete from detail where contact_no=@contactNo", con);
cmd.Parameters.AddWithValue("@contactNo", TexBo_num.Text);
于 2013-09-22T11:06:36.293 回答