title: Inserting "NULL" or "NOT NULL" into ASP.NET parameterized queries
body: <p>I have an asp DropDownList that is used to filter database results. One of my filters is used to check if a column is NULL or NOT NULL:</p>
  
  <pre><code>&lt;asp:DropDownList runat="server" id="activeFilter" CssClass="form-control"  AutoPostBack="false" &gt;
    &lt;asp:ListItem selected="True" value=""&gt;-- Filter By Active/Inactive &lt;/asp:ListItem&gt;
    &lt;asp:ListItem value="NOT NULL"&gt;Active&lt;/asp:ListItem&gt;
    &lt;asp:ListItem value="NULL"&gt;Inactive&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>I then try to insert it into a parameterized query like so:</p>
  
  <pre><code>//called from another method
  
  string query = ".... AND Status=@statusFilter ...."
  SqlConnection conn = new SqlConnection(connString)
  SqlCommand command = new SqlCommand(query, conn)
  command.Parameters.AddWithValue("@statusFilter", statusFilter.SelectedValue);
  
  //other stuff, make sql call
  </code></pre>
  
  <p>This process works for other filter values, something like </p>
  
  <pre><code>"... AND Name=@nameFilter ..."
  </code></pre>
  
  <p>Where nameFilter might be "John", "Tim", "Amy", etc. so I'm assuming this has something to do with the fact that NULL and NOT NULL shouldn't actually be strings. Any easy solution for this? I see I can add DBNull.Value but what about NOT NULL?</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><strong>EDIT:</strong>
  Sorry everyone, I made a mistake in my first post - I copied the wrong query string. My query string is actually</p>
  
  <pre><code>"... AND Date_Completed IS @activeFilter ..." 
  </code></pre>
  
  <p>I know I cant say Column=Null, so again I apologize. I'm going to run through the suggestions right now and update everyone. </p>
  
  <p><strong>EDIT 2:</strong>
  Okay so the issue is that you cannot treat NULL / NOT NULL as parameters. I was hoping I could use it as a parameter as I had a number of utility functions to generate the final query based on a many different filters. Ultimately, this did not work, and I needed to alter my methods and insert the entire " IS NULL " or "IS NOT NULL" directly using an If/Else block.</p>