title: How can I use the Like Operator with a Parameter in a SQLite query?
body: <p>I can get the result I expect by entering this in LINQPad:</p>
  
  <pre><code>SELECT * FROM WorkTable WHERE WTName LIKE "DSD__20090410014953000%"
  </code></pre>
  
  <p>(it shows me the record which has a WTName value of DSD__20090410014953000.xml")</p>
  
  <p>But trying to do this programmatically is proving trying. I tried:</p>
  
  <pre><code>const string qry = "SELECT SiteNum FROM WorkTable WHERE WTName LIKE @wtName%";
  using (SQLiteConnection con = new SQLiteConnection(HHSUtils.GetDBConnection()))
  {
      con.Open();
      SQLiteCommand cmd = new SQLiteCommand(qry, con);
      cmd.Parameters.Add(new SQLiteParameter("wtName", tableName));
      siteNum = Convert.ToInt32(cmd.ExecuteScalar());
  }
  </code></pre>
  
  <p>...but it causes the app to crash, and my log file tells me why:</p>
  
  <pre><code>Message: From application-wide exception handler: System.Data.SQLite.SQLiteException: SQL logic error or missing database
  near "%": syntax error
  </code></pre>
  
  <p>So maybe it thinks the query parameter is named "wtName%" instead of "wtName"; but separating the parameter and the "whatever" opertor ("%") with a space doesn't work, either.</p>
  
  <p>I could go retro/kludgy by just embedding the query parameter into the string like so:</p>
  
  <pre><code>const string qry = String.Format("SELECT SiteNum FROM WorkTable WHERE WTName LIKE {0}%", tableName);
  </code></pre>
  
  <p>...and doing without the query parameter altogether, but I'm afraid if I did that <a href="https://haveibeenpwned.com/" rel="noreferrer">Troy Hunt</a> would show up at my house and flail me with a bedrail while railing about SQL Injection.</p>
  
  <p>How can I get my data and simultaneously write safe code?</p>