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 Cardserial=@Cardserial", 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

PostgreSQL: deleting rows referenced from another table

From Java

Deleting all rows from Cassandra cql table

From Dev

Deleting rows from 3 tables in MySQL table

From Dev

Issue deleting rows from displayed table

From Dev

Deleting rows from multiple tables with jQuery

From Dev

Deleting columns from multiple table having relationship

From Dev

Deleting rows in HTML table

From Dev

Deleting multiple rows in datagridview

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

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

Dynamically added table rows not deleting

From Dev

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

From Dev

Deleting rows of data for multiple variables

From Dev

deleting a row from 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

Related Related

  1. 1

    Deleting multiple rows from a table

  2. 2

    Deleting multiple rows from TableView

  3. 3

    PostgreSQL: deleting rows referenced from another table

  4. 4

    Deleting all rows from Cassandra cql table

  5. 5

    Deleting rows from 3 tables in MySQL table

  6. 6

    Issue deleting rows from displayed table

  7. 7

    Deleting rows from multiple tables with jQuery

  8. 8

    Deleting columns from multiple table having relationship

  9. 9

    Deleting rows in HTML table

  10. 10

    Deleting multiple rows in datagridview

  11. 11

    How does deleting rows from a table affect its indexes?

  12. 12

    Issue with Deleting rows from my second Table in my page

  13. 13

    c# deleting duplicate rows from data table

  14. 14

    Deleting all rows from table that share the same ID

  15. 15

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

  16. 16

    Deleting many rows from a big table MySql 5.5.46

  17. 17

    Deleting all rows from table, and resetting auto incrementation

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

    Dynamically added table rows not deleting

  22. 22

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

  23. 23

    Deleting rows of data for multiple variables

  24. 24

    deleting a row from table

  25. 25

    Insert multiple rows into a MySQL database from a table

  26. 26

    Insert multiple rows from select into another table

  27. 27

    Field involving multiple rows from another table

  28. 28

    Create multiple rows in table from array?

  29. 29

    MYSQL - UPDATE multiple rows from another table

HotTag

Archive