[英]Deleting multiple rows from a table
我有一個表,我想刪除具有特定卡序列的所有行。 有多個行具有相同的卡序列。所以我寫了這段代碼,但似乎不起作用:
try
{
using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
con.Open();
SqlCommand command2 = new SqlCommand("DELETE FORM DevInOut where Cardserial='" + textBox5.Text + "'", con);
command2.ExecuteNonQuery();
con.Close();
}
}
catch (SqlException ex)
{
}
如何確保刪除所有行。 我應該使用程序嗎? 我該如何使用程序?
將您的FORM
更改為FROM
。
請始終使用參數化查詢 。 這種字符串連接對SQL注入攻擊是開放的。
using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
con.Open();
SqlCommand command2 = new SqlCommand("DELETE FROM DevInOut where Cardserial=@Cardserial", con);
commdand2.Parameters.AddWithValue("@Cardserial", textBox5.Text);
command2.ExecuteNonQuery();
con.Close();
}
從DELETE (Transact-SQL)
了解更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.