连字符/短划线打破搜索

时间:2012-08-13 08:58:25

标签: c# asp.net sql

当名称包含连字符时,它无法获取正确的行。 它实际上并没有取任何东西

XAML:

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=Entities"
        DefaultContainerName="Entities" EnableFlattening="False" EntitySetName="CustomerClassifications">
    </asp:EntityDataSource>

        <div class="searchWrapper">
            Search
            <asp:Panel DefaultButton="btnSearch" runat="server" ID="pnlSearch">
            <asp:TextBox ID="tbxSearch" runat="server" CssClass="tbxSearch">
            </asp:TextBox>
            <asp:Button ID="btnSearch" runat="server" CssClass="btnSearch" Text="Search" />
            </asp:Panel>
        </div>

代码背后:

            this.EntityDataSource1.WhereParameters.Clear();
            if (string.IsNullOrEmpty(tbxSearch.Text))
            {
                this.EntityDataSource1.Where = "1 = 1";
            }
            else
            {
                this.EntityDataSource1.Where = "it.Name =  @Name ";
            }

1 个答案:

答案 0 :(得分:0)

您正在清除WhereParameters,但在第二个where子句中使用参数@Name。我认为你不应该清除WhereParameters