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 Dev

Deleting multiple rows from a table

From Dev

Deleting multiple rows from TableView

From Dev

Deleting rows from multiple tables with jQuery

From Java

Deleting all rows from Cassandra cql table

From Dev

PostgreSQL: deleting rows referenced from another table

From Dev

Deleting rows from 3 tables in MySQL table

From Dev

Issue deleting rows from displayed table

From Dev

Deleting columns from multiple table having relationship

From Dev

Deleting multiple rows in datagridview

From Dev

Deleting rows in HTML table

From Dev

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

From Dev

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

From Dev

How does deleting rows from a table affect its indexes?

From Dev

Issue with Deleting rows from my second Table in my page

From Dev

c# deleting duplicate rows from data 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

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

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

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

Create multiple rows in table from array?

From Dev

MYSQL - UPDATE multiple rows from another table

From Dev

Inserting multiple rows to database table from a form

From Dev

Combine multiple rows in one from same table

From Dev

Inserting multiple rows to database table from a form

Related Related

  1. 1

    Deleting multiple rows from a table

  2. 2

    Deleting multiple rows from TableView

  3. 3

    Deleting rows from multiple tables with jQuery

  4. 4

    Deleting all rows from Cassandra cql table

  5. 5

    PostgreSQL: deleting rows referenced from another table

  6. 6

    Deleting rows from 3 tables in MySQL table

  7. 7

    Issue deleting rows from displayed table

  8. 8

    Deleting columns from multiple table having relationship

  9. 9

    Deleting multiple rows in datagridview

  10. 10

    Deleting rows in HTML table

  11. 11

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

  12. 12

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

  13. 13

    How does deleting rows from a table affect its indexes?

  14. 14

    Issue with Deleting rows from my second Table in my page

  15. 15

    c# deleting duplicate rows from data table

  16. 16

    Deleting all rows from table that share the same ID

  17. 17

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

  18. 18

    Deleting many rows from a big table MySql 5.5.46

  19. 19

    Deleting all rows from table, and resetting auto incrementation

  20. 20

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

  21. 21

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

  22. 22

    Insert multiple rows into a MySQL database from a table

  23. 23

    Insert multiple rows from select into another table

  24. 24

    Field involving multiple rows from another table

  25. 25

    Create multiple rows in table from array?

  26. 26

    MYSQL - UPDATE multiple rows from another table

  27. 27

    Inserting multiple rows to database table from a form

  28. 28

    Combine multiple rows in one from same table

  29. 29

    Inserting multiple rows to database table from a form

HotTag

Archive