C# Parameterized Query MySQL with `in` clause

前端 未结 7 1800
感情败类
感情败类 2020-12-03 15:36

I am in the process of converting several queries which were hard-coded into the application and built on the fly to parameterized queries. I\'m having trouble with one part

7条回答
  •  庸人自扰
    2020-12-03 16:21

    Old question, but in case anyone comes across this via Google, here's what I use:

    int status = 4;  
    string ids = "1,14,145,43";      
    
    m.Parameters.AddWithValue("@Status", status);
    m.Parameters.AddWithValue("@IDs", ids);
    
    UPDATE TABLE_1 SET STATUS = @Status WHERE FIND_IN_SET(ID, @IDs) > 0;
    

    Note: FIND_IN_SET is a mySQL specific function.

    Credit, where credit is due: See this question: Add List to a mysql parameter

提交回复
热议问题