Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从表中删除多行_C#_Sql_Sql Server - Fatal编程技术网

C# 从表中删除多行

C# 从表中删除多行,c#,sql,sql-server,C#,Sql,Sql Server,我有一个表,我想删除具有特定序列卡的所有行。有多行具有相同的卡序列。因此我编写了此代码,但似乎不起作用: try { using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString)) { con.Open(); SqlCommand command2 = new SqlCommand("DELETE FORM DevInOut where

我有一个表,我想删除具有特定序列卡的所有行。有多行具有相同的卡序列。因此我编写了此代码,但似乎不起作用:

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)
{
}
如何确保删除所有行。我应该使用程序吗?如何使用程序?

将表单更改为

请始终使用。这种类型的字符串连接对攻击是开放的

阅读更多信息,请将表单更改为

请始终使用。这种类型的字符串连接对攻击是开放的


读更多的

哦,我的天啊。多么愚蠢的错误啊。谢谢你关于参数化查询的提示。哦,天哪。多么愚蠢的错误啊。感谢您提供有关参数化查询的提示。
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();
}