I have an array of integers. I want to use that array in my selectCommand to form an "IN" clause ("WHERE Cli.ID IN (1,2,3,4)"). I have tried to turn the array into a string (code below) but that (reasonably enough) doesn't work.
I found this KB article from 2005 but the proposed workaround made my eyes bleed.
Is there an easy and elegant way to do this that I'm missing? Surely it's a common enough thing to want to do?
string iDlist = "";
for (int i = 0; i < MyIDs.Length; i++)
{
iDlist += Convert.ToString(MyIDs[i]) + (i == 0 ? "" : ",");
}
this.sqlDataAdapter1.SelectCommand.CommandText = StandardQuery + @" where Cli.ID in (@iDlist)";
this.sqlDataAdapter1.SelectCommand.Parameters.Clear();
this.sqlDataAdapter1.SelectCommand.Parameters.Add(new SqlParameter("@iDlist", SqlDbType.VarChar));
this.sqlDataAdapter1.SelectCommand.Parameters["@iDlist"].Value = iDlist;