WHERE IN (array of IDs)

后端 未结 9 1269
暖寄归人
暖寄归人 2020-11-28 11:16

I have webservice which is passed an array of ints. I\'d like to do the select statement as follows but keep getting errors. Do I need to change the array to a string?

9条回答
  •  星月不相逢
    2020-11-28 11:35

    I use that approach and works for me.

    My variable act = my list of ID's at string.

    act = "1, 2, 3, 4"

     command = new SqlCommand("SELECT x FROM y WHERE x.id IN (@actions)", conn);    
     command.Parameters.AddWithValue("@actions", act);
     command.CommandText = command.CommandText.Replace("@actions", act);
    

提交回复
热议问题