Good afternoon, I have a list of strings that contains the codes to add to an SQL query in an in: Example:
List<string> container = new List<string>();
container.Add("2");
container.Add("3");
container.Add("5");
container.Add("12");
container.Add("214");
container.Add("A324");
container.Add("SD3434");
string cIn = string.Join(",", container);
string lcSql = "SELECT articulo from ofertas WHERE articulo in(" +cIn + ")";
This gives me: SELECT articulo from ofertas WHERE articulo in(2,3,5,12,214,A324,SD3434)
but article is a field of type char(10)
, so I would need to quote all the values of the result of string.Join
but I can't find a way to do it. Can I do this using this method, or am I looking for another way? Thanks.
You have several options. A very simple one is to use
Select
to concatenate the quotes:This returns the following with your example:
Another more elegant option using
String.Format
: