title: How to use parameterized queries correctly?
body: <p>I've been working on this now for 2 hours straight and read through a lot of so question but I cant see where or why my OleDbCommand is not working the way it should.<br>
  I wrote this code as a merge of all the question and answers i've seen:   </p>
  
  <pre><code>using (var connection = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;" + @"data source= *path to mdp*"))
  {
    try
    {
      connection.Open();
      foreach (KeyValuePair&lt;string, string&gt; pair in dictionary)
      {
          string query = "SELECT * FROM mytable WHERE db_id=?";
          var command = new OleDbCommand(query, connection);
          //command.Parameters.Add(new OleDbParameter("@ID", pair.Value));
          command.Parameters.Add("?", OleDbType.BSTR).Value = pair.Value;
          var reader = command.ExecuteReader();
          while (reader.Read())
          {
              Console.WriteLine(reader[0].ToString());
          }
          reader.Close();
      }
      connection.Close();
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
  }
  </code></pre>
  
  <p>However this gives me the "No Value given for one or more required Parameteres" Error. If i try the now commented line</p>
  
  <pre><code>command.Parameters.Add(new OleDbParameter("@ID", pair.Value));
  </code></pre>
  
  <p>and comment the other, the outcome is the exact same.<br>
  But if I use both those lines the reader reads but gives me every entry in my table column and not just the desired matching with pair.Value.  </p>
  
  <p>The KeyValuePair is nothing but a Tuple of a string id from my program as a key and its corresponding id in the database as value.  </p>
  
  <p>I'm thankful for any help or suggestion.</p>