locked
Wildcard in a WHERE clause RRS feed

  • Question

  • User559005402 posted

    Is it possible to use a wildcard in an SQLdatasource WHERE clause? I have an RBL and datasource like this:

    <asp:RadioButtonList ID="FundType_RBL" runat="server" 
    						AutoPostBack="True" 
    						DataSourceID="FundTypeDataSource"
    						DataTextField="FundType" 
    						DataValueField="FundType" 
    						AppendDataBoundItems="True">
    						<asp:ListItem Selected="True" Text="All Fundtypes" Value="*" />
    					</asp:RadioButtonList>
    					
    		<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TIPConnectionString %>"
    			SelectCommand="SELECT * FROM [ApprovedFunding] WHERE ([Fundtype] = @Fundtype) ORDER BY [YEAR], [AMOUNT]" 
    			
    			<SelectParameters>
    				<asp:ControlParameter ControlID="FundType_RBL" DefaultValue="*" Type="String" Name="Fundtype" />
    			</SelectParameters>
    		</asp:SqlDataSource>

     

     

     

    but the wildcard portion doesn't seem to work as it produces no records when it should produce all records.

    Thanks

    Friday, October 21, 2011 2:32 PM

Answers

  • User3690988 posted

    Try changing the default value to % and use the LIKE clause... SELECT * FROM [ApprovedFunding] WHERE ([Fundtype] LIKE @Fundtype

    Warning, I did not test this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 21, 2011 2:47 PM

All replies

  • User3690988 posted

    Try changing the default value to % and use the LIKE clause... SELECT * FROM [ApprovedFunding] WHERE ([Fundtype] LIKE @Fundtype

    Warning, I did not test this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 21, 2011 2:47 PM
  • User559005402 posted

    Seems to work. Thanks for the tip.

    Friday, October 21, 2011 3:53 PM