I am trying to pass array parameter to SQL commnd in C# like below, but it does not work. Does anyone meet it before?
string sqlCommand = \"SELECT * from Ta
Here is a minor variant of Brian's answer that someone else may find useful. Takes a List of keys and drops it into the parameter list.
//keyList is a List
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
string sql = "SELECT fieldList FROM dbo.tableName WHERE keyField in (";
int i = 1;
foreach (string key in keyList) {
sql = sql + "@key" + i + ",";
command.Parameters.AddWithValue("@key" + i, key);
i++;
}
sql = sql.TrimEnd(',') + ")";