0

我有一个 datalist 控件,当我使用查询生成器测试数据源查询时,它连接到 SQLDataSource,它返回数据集,但是当我在任何浏览器中运行网站时,查询不返回数据集。

It seems like the website is not recompiling properly however i am not getting any build errors.

有没有人对可能的解决方案有任何想法。

提前致谢

我的 sqldatasource 代码是-

<asp:SqlDataSource ID="SqlDataSourceSearch" runat="server" ConnectionString="<%$ ConnectionStrings:BazaarCeramicsConnectionString %>" 
        SelectCommand="SELECT Categories.Name, Products.ProductID, Products.Name AS Expr1 FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID WHERE (Products.Name LIKE '%' + @SearchQuery + '%')">
        <SelectParameters>
        <asp:QueryStringParameter Name="SearchQuery" QueryStringField="search" 
            Type="String" />
    </SelectParameters>
    </asp:SqlDataSource>

我的数据列表代码是-

<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" DataSourceID="SqlDataSourceSearch">
        <ItemTemplate>
            Name:
            <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            <br />
            ProductID:
            <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
            <br />
            Expr1:
            <asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
            <br />


这是我的输入-

<div class="searchBox">
                    <asp:TextBox ID="SearchTextBox" runat="server"></asp:TextBox>
                    <asp:Button ID="SearchButton" runat="server" onclick="Button1_Click" Text="Search" />
                    <a href="ShoppingCart.aspx"><img id="cartIcon" src="Images/shoppingCartIcon.png" /></a>
               </div>

这是后面的代码

 protected void Button1_Click(object sender, EventArgs e)
{
    string SearchTerm = SearchTextBox.Text;
    Response.Redirect("SearchResults.aspx?SearchQuery=" + Server.UrlEncode(SearchTerm));
}

这是我的连接字符串-

<add name="BazaarCeramicsConnectionString" connectionString="Data Source=CATHERINE\SQLEXPRESS;Initial Catalog=BazaarCeramics;User ID=****;Password=******"
  providerName="System.Data.SqlClient" />
4

1 回答 1

1
(Products.Name LIKE '%' + @SearchQuery + '%')
于 2013-11-11T17:54:56.113 回答