2

I know that a question like this already exists in: How to pass parameter to sql 'in' statement?

but the answers didn't help me, so I am asking for your guidance.

How do you pass a string array as parameter to a Npgsql statement? Let's say the statement goes something like this:

string[] names = new string[] { "one", "two" };

Adapter.SelectCommand.CommandText("Select something.name from something (a lot of inner joins) where something_else.name in (:names) group by something.name having count(*)=2; ");

Community
  • 1
  • 1
boo_boo_bear
  • 189
  • 1
  • 4
  • 14

2 Answers2

2

Try:

where something_else.name = any(:names)
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
frost
  • 64
  • 5
0

I am not familiar with the exact syntax of npgsql, but I can tell you how to proceed.

From your string array names create a string that looks like "'one', 'two'". Be sure you have the single quotes delimited them.

Then, when you create the command string, don't use variable substitution. Instead, just concatenate the string you just created between the ( and ) after the in statement. That is, directly insert them into the string.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • That was a solution I wanted to follow, but I kinda didn't want to bother myself with concatenating strings and such. Thanks for reply! – boo_boo_bear May 21 '13 at 09:19