Set SqlDataSource parameter to null
<p>How do you set a parameter passed to a SqlDataSource to be null?  I have the code below where the parameter "@var1" is set from a TextBox.  However, if that value is not defined I need to set "@var1" to be null so that the <a href="https://msdn.microsoft.com/en-us/library/ms190349.aspx" rel="noreferrer">coalesce</a> returns true.</p>

<p>Is there a way to do this or am I going about it the wrong way?</p>

<p>I've also tried setting the <code>DefaultValue="null"</code> and <code>dsABC.SelectParameters["@var1"]=null</code> which both lead to "Input string was not in a correct format" errors.</p>

<pre><code>   &lt;asp:SqlDataSource ID="dsABC" runat="server" ConnectionString="&lt;%$ ConnectionStrings:abc123 %&gt;" 
   SelectCommand=" SELECT   col1, col2, col3                        
                   FROM table1 as T1
                   WHERE   COALESCE(@var1, T.ID) = T.ID"&gt;
     &lt;SelectParameters&gt;
        &lt;asp:ControlParameter Name="var1" ControlID="inputA" PropertyName="Value" DefaultValue="0" Type="Int16" /&gt;
     &lt;/SelectParameters&gt;  
   &lt;/asp:SqlDataSource&gt;
</code></pre>