Reputation: 167
I'm trying to delete a series of rows in a MySQL table from a list of ID's in C#. There's an employeeID row in the table. Basically my question is what kind of syntax would I use?
Upvotes: 3
Views: 6535
Reputation: 171519
If you are using Dapper it would look something like this:
int[] ids = new int[]{1,2,3};
DbConnection cn = ... //open connection here
cn.Execute("delete from Employee where employeeID in @ids", new {ids});
Upvotes: 4
Reputation: 56779
You would probably use an IN
clause in your DELETE
:
DELETE FROM `EmployeeTable` WHERE EmployeeID IN (2, 3, 4, 5, ...)
This could be implemented with the String.Join
method to generate the list:
var query = "DELETE FROM `EmployeeTable` WHERE EmployeeID IN (" +
String.Join(",", myArray) + ")";
Upvotes: 6