Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see 2 problems here: 1) list.ToString() doesn't do what you expect. Try this:</p> <pre><code>List&lt;int&gt; foo = new List&lt;int&gt;(); foo.Add(1); foo.Add(4); string x = foo.ToString(); </code></pre> <p>The value of "x" will be "System.Collections.Generic.List`1[System.Int32]" not "1,4" To create a comma separated list, use string.Join().</p> <p>2) OleDbParameter does not understand arrays or lists. You have to do something else. Let me explain:</p> <p>Suppose that you successfully use string.Join() to create the parameter. The resulting SQL will be:</p> <pre><code>SELECT * FROM sp_feedbacks WHERE forumId IN ('1,4') </code></pre> <p>The OLEDB provider knows that strings must have quotation marks around them. This is to protect you from SQL injection attacks. But you didn't want to pass a string: you wanted to pass either an array, or a literal unchanged value to go into the SQL.</p> <p>You aren't the first to ask this question, but I'm afraid OLEDB doesn't have a great solution. If it were me, I would discard OLEDB entirely and use dynamic SQL. However, a Google search for "parameterized SQL array" resulted in some very good solutions here on Stack Overflow:</p> <p><a href="https://stackoverflow.com/questions/182060/where-in-array-of-ids">WHERE IN (array of IDs)</a></p> <p><a href="https://stackoverflow.com/questions/1069311/passing-an-array-of-parameters-to-a-stored-procedure">Passing an array of parameters to a stored procedure</a></p> <p>Good Luck! Post which approach you go with!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload