2013-09-22 26 views
-1

插入,更新和刪除後我想我的TEXT.BOX空......所以我該怎麼做...... ????關於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(); 
    } 
} 

回答

0

問題不是很清楚,只需在執行comman後設置它的Text屬性即可。

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

請注意,您應該使用SQL參數來prevent sql-injection attacks

SqlCommand cmd = new SqlCommand("delete from detail where [email protected]", con); 
cmd.Parameters.AddWithValue("@contactNo", TexBo_num.Text);