title: SQL Server: Parameter is not replaced
body: <p>I've got a fully functionable (secure) session to a SQL Server database (version 10.50.4000). This is stored in a public variable:</p>
  
  <pre><code>SqlConnection conn = new SqlConnection();
  </code></pre>
  
  <p>I only want to run <code>SELECT</code> queries. For anything else, the user account got no rights.</p>
  
  <p>The queries are built with only one user entry, which is inserted into a simple Text Box.</p>
  
  <p>Unfortunately I must not tell you the original command text. So I make it simple for you:</p>
  
  <pre><code>function print_users(string filtervalue)
  {
      SqlCommand cmd = null;
      cmd = new SqlCommand("SELECT users From groups WHERE group_name LIKE '%@fv%'", this.conn)
  
      cmd.Parameters.Add("@fv", SqlDbType.NVarChar);
      cmd.Parameters["@fv"].Value=filtervalue;
  
      rdr = cmd.ExecuteReader();
  
      while(rdr.Read())
      {
          //Do something with the answer from the DB
      }
  }
  </code></pre>
  
  <p>But this does not do the trick. I also tried <code>AddWithValue</code>, but I got no luck.</p>
  
  <p>When creating a stop-point on the line, where <code>@fv</code> should be replaced, I can go through the code line-by-line. And I can see that the command, where <code>@fv</code> should be replaced, is processed with no error. But <code>@fv</code> is not replaced (or at least I cannot see the replacement in the debug console).</p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT:</p>
  
  <p>thank you for your replies. Leaving out the single quotes ( ' ) did the trick.</p>
  
  <p>And I also learned that this is not a string replacement. Thank you.</p>
  
  <p>Just one word: The connection is not left open all the time. It's immediately closed, when it's not needed any more; and re-established when needed again - I just forgot to write that into my sample code.</p>
  
  <p>Again: Thank you for your help!</p>