Convert an array of integers for use in a SQL “IN” clause

前端 未结 8 2223
死守一世寂寞
死守一世寂寞 2021-01-05 03:44

Surely there is a framework method that given an array of integers, strings etc converts them into a list that can be used in a SQL \"IN\" clause?

e.g.

8条回答
  •  时光取名叫无心
    2021-01-05 04:24

    If you don't have access to the .NET 3.5 extension methods, you can do this:

    StringBuilder sb = new StringBuilder();
    sb.Append('(');
    
    foreach (int i in values) {
        sb.Append(i).Append(',');
    }
    
    // remove final ,
    sb.Length -= 1;
    sb.Append(')');
    
    string inValue = sb.ToString();
    

    Which'll work on .NET 2

提交回复
热议问题