title: SQL LIKE query to C# code
body: <p>I need to use the following query in my C# code:</p>
  <pre><code>SELECT AVG(Percent) 
  From Table1
  Where code Like &quot;Sport&quot; and Year Like&quot;2011&quot; and Sitting Like&quot;June&quot;;
  </code></pre>
  <p>I did it like this:</p>
  <pre><code>&quot;SELECT AVG(Percentage) FROM MasterTable WHERE Code LIKE &quot; + comboBoxSubject.Text +
  &quot;AND Year LIKE &quot;+dateTimePicker1 +&quot; AND Sitting LIKE June&quot;
  </code></pre>
  <p>but i get an exception probably because the parameters are extracted from different controls and are not placed in inverted commas.</p>
  <p>Can anyone help me ?</p>
  <h3>ANSWER</h3>
  <p>That is the query that worked for me:</p>
  <pre><code>&quot;SELECT AVG(Percent) FROM MasterTable WHERE Code LIKE '&quot; + comboBoxSubject.Text + &quot;' AND Year LIKE '&quot; + dateTimePicker1.Value.Year + &quot;' AND Sitting LIKE 'June'&quot;
  </code></pre>