Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I <em>think</em> you are fine: According to the <a href="http://msdn.microsoft.com/en-us/library/ms175055.aspx" rel="nofollow noreferrer">SQL Server Books Online</a>, a solitary single quote seems to be the only way to <em>exit</em> a quoted string that was started with a single quote. Thus, replacing <code>'</code> with <code>''</code> should suffice to avoid SQL injection through <code>string</code> variables.</p> <p>I cannot think of any way to inject SQL through other, <em>non-string</em> native C# data types, if they are <em>properly</em> (locale-invariant) converted to strings.</p> <p>Nevertheless, parameterized queries are the "recommended" solution. At the moment, your application seems to be organized like this:</p> <ol> <li>Part A creates a WHERE statement based on user input.</li> <li>A string containing this WHERE statement is passed to Part B.</li> <li>Part B adds SELECT etc. and sends it to SQL Server.</li> </ol> <p>Would it be an option to rewrite your application like this?</p> <ol> <li>Part A creates a parameterized WHERE statement plus a set of parameters based on user input.</li> <li>A string containing the WHERE statement plus a Hashtable (or something similar) containing the parameters is passed to Part B.</li> <li>Part B creates a command, adds SELECT etc., adds the parameters and sends it to SQL Server.</li> </ol> <p>I was in a similar situation and solved it by creating a <code>SubSQL</code> class, which basically contains a parameterized string with the CommandText and a hash table with the parameters. You could then use this as <code>mySubSQL.CommandText += ...</code>, <code>mySubSQL.Parameters("@myfield") = myValue</code> and <code>mySubSQL.MergeInto(myCommand)</code> (the implementation should be obvious and straight-forward).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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