Deleting multiple rows from a table

saad

I have a table and I want to delete all rows with a specific card serial . There are multiple rows with the same card serial .So I wrote this code but it seems that's not working:

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)
{
}

how can assure all the rows will be deleted . Should I use procedure? How do I use procedure?

Soner Gönül

Change your FORM to FROM.

And please always use parameterized queries instead. This kind of string concatenations are open for SQL Injection attacks.

using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
   con.Open();
   SqlCommand command2 = new SqlCommand("DELETE FROM DevInOut where [email protected]", con);
   commdand2.Parameters.AddWithValue("@Cardserial", textBox5.Text);
   command2.ExecuteNonQuery();
   con.Close();
}

Read more from DELETE (Transact-SQL)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Deleting all rows from Cassandra cql table

From Dev

Issue with Deleting rows from my second Table in my page

From Dev

Deleting multiple rows from a table

From Dev

How does deleting rows from a table affect its indexes?

From Dev

Trigger to delete rows from related tables before deleting rows from actual table

From Dev

Deleting multiple rows in datagridview

From Dev

Deleting columns from multiple table having relationship

From Dev

Deleting rows from 3 tables in MySQL table

From Dev

Inserting multiple rows to database table from a form

From Dev

Combine multiple rows in one from same table

From Dev

Create multiple rows in table from array?

From Dev

Deleting rows from multiple tables with jQuery

From Dev

PostgreSQL: deleting rows referenced from another table

From Dev

Python - NumPy - deleting multiple rows and columns from an array

From Dev

Insert multiple rows into a MySQL database from a table

From Dev

Insert multiple rows from select into another table

From Dev

Field involving multiple rows from another table

From Dev

Trying to delete selected row from datagridview but it is deleting multiple rows

From Dev

c# deleting duplicate rows from data table

From Dev

MYSQL - UPDATE multiple rows from another table

From Dev

Deleting all rows from table that share the same ID

From Dev

Efficiently deleting rows from one table where not matching another [MySQL]

From Dev

Deleting many rows from a big table MySql 5.5.46

From Dev

Issue deleting rows from displayed table

From Dev

Inserting multiple rows to database table from a form

From Dev

Deleting all rows from table, and resetting auto incrementation

From Dev

MySQL: deleting rows based on a condition with data from another table and NO JOIN

From Dev

Deleting multiple rows from TableView

From Dev

Deleting rows in HTML table

Related Related

  1. 1

    Deleting all rows from Cassandra cql table

  2. 2

    Issue with Deleting rows from my second Table in my page

  3. 3

    Deleting multiple rows from a table

  4. 4

    How does deleting rows from a table affect its indexes?

  5. 5

    Trigger to delete rows from related tables before deleting rows from actual table

  6. 6

    Deleting multiple rows in datagridview

  7. 7

    Deleting columns from multiple table having relationship

  8. 8

    Deleting rows from 3 tables in MySQL table

  9. 9

    Inserting multiple rows to database table from a form

  10. 10

    Combine multiple rows in one from same table

  11. 11

    Create multiple rows in table from array?

  12. 12

    Deleting rows from multiple tables with jQuery

  13. 13

    PostgreSQL: deleting rows referenced from another table

  14. 14

    Python - NumPy - deleting multiple rows and columns from an array

  15. 15

    Insert multiple rows into a MySQL database from a table

  16. 16

    Insert multiple rows from select into another table

  17. 17

    Field involving multiple rows from another table

  18. 18

    Trying to delete selected row from datagridview but it is deleting multiple rows

  19. 19

    c# deleting duplicate rows from data table

  20. 20

    MYSQL - UPDATE multiple rows from another table

  21. 21

    Deleting all rows from table that share the same ID

  22. 22

    Efficiently deleting rows from one table where not matching another [MySQL]

  23. 23

    Deleting many rows from a big table MySql 5.5.46

  24. 24

    Issue deleting rows from displayed table

  25. 25

    Inserting multiple rows to database table from a form

  26. 26

    Deleting all rows from table, and resetting auto incrementation

  27. 27

    MySQL: deleting rows based on a condition with data from another table and NO JOIN

  28. 28

    Deleting multiple rows from TableView

  29. 29

    Deleting rows in HTML table

HotTag

Archive