当我使用查询构建器测试数据源查询时,我有一个连接到SQLDataSource的datalist控件,它返回数据集但是当我在任何浏览器中运行网站时,查询都不会返回数据集。
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>
我的datalist代码是 -
<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" />
答案 0 :(得分:1)
(Products.Name LIKE '%' + @SearchQuery + '%')