Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET - SQLDataSource - FilterExpression - Problem with Empty Strings
    primarykey
    data
    text
    <p>In this test application, I am filtering by two ControlParameters. As you can see in the first codeblock, both parameters have a default value of %. This code works great. However, in the second code block, please note that the Default Values are eliminated. The second code block works as long as neither Textbox's text is blank. For some reason, when .NET evaluates the filter expression and inserts "" into the expression, it seems to bug out and case none of my results to be filtered. </p> <p>I am able to verify this behavior by setting the defaultvalue="" for each ControlParameter.</p> <p>Obviously I have found a workaround, but I would like to know why the FilterExpression breaks down when an empty string is provided.</p> <p>Any ideas?</p> <p><strong>Code Block 1:</strong></p> <pre><code> &lt;asp:SqlDataSource ID="Customer_Data" runat="server" ConnectionString='&lt;%$ ConnectionStrings:connectionString %&gt;' SelectCommand="SELECT Station, StoreFront, CustomerID as CustID FROM vStations" ProviderName="System.Data.SqlClient" FilterExpression="StoreFront LIKE '%{0}%' and CustID LIKE '{1}%'" EnableCaching="True" CacheDuration="60"&gt; &lt;FilterParameters&gt; &lt;asp:ControlParameter ControlID="TextBox1" PropertyName="Text" DefaultValue="%" /&gt; &lt;asp:ControlParameter ControlID="TextBox2" PropertyName="Text" DefaultValue="%" /&gt; &lt;/FilterParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p><strong>Code Block 2:</strong></p> <pre><code> &lt;asp:SqlDataSource ID="Customer_Data" runat="server" ConnectionString='&lt;%$ ConnectionStrings:connectionString %&gt;' SelectCommand="SELECT Station, StoreFront, CustomerID as CustID FROM vStations" ProviderName="System.Data.SqlClient" FilterExpression="StoreFront LIKE '%{0}%' and CustID LIKE '{1}%'" EnableCaching="True" CacheDuration="60"&gt; &lt;FilterParameters&gt; &lt;asp:ControlParameter ControlID="TextBox1" PropertyName="Text" /&gt; &lt;asp:ControlParameter ControlID="TextBox2" PropertyName="Text" /&gt; &lt;/FilterParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre>
    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.
 

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