0

I have a textbox with id = txt_SearchLibrary which is also my controlparameter that I am using to filter my sqldatasource, I want to get all the results when I don't type something in my searchtext box, but below codes results 0 rows. I tried 2 way but both didn't work.

first one:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDbConn %>"
            SelectCommand="SELECT * FROM [Books] WHERE ([BookName] LIKE '%' + @searchText + '%') OR  @searchText IS NULL">
    <SelectParameters>
        <asp:ControlParameter ControlID="txt_SearchLibrary" Name="searchText"
                    PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

second one:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDbConn %>"
            SelectCommand="SELECT * FROM [Books] WHERE ([BookName] LIKE '%' + @searchText + '%')">
    <SelectParameters>
        <asp:ControlParameter ControlID="txt_SearchLibrary" DefaultValue="" Name="searchText"
                    PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
CAbbott
  • 8,078
  • 4
  • 31
  • 38
HOY
  • 1,067
  • 10
  • 42
  • 85

1 Answers1

0

The Text property is probably "" or String.Empty, rather than NULL which you're checking for in your SQL statement.

mellodev
  • 1,597
  • 12
  • 20