简体   繁体   English

VB.net中的搜索查询需要帮助吗?

[英]Search Queries in VB.net Help Required?

I am trying to perform a search query using drop down boxes with a button named search. 我正在尝试使用带有名为search的按钮的下拉框执行搜索查询。 I want it to bring up the data that is searched for. 我希望它调出要搜索的数据。 I dont know where to start from, i have looked around for some coding and different ways to do it but they seem complicated, this is the bit of ASP that is my weakness, need some assistance and guidance. 我不知道从哪里开始,我一直在寻找一些编码和不同的方法来做,但是它们看起来很复杂,这是ASP的一点,这是我的弱点,需要一些帮助和指导。 below is the code for the page; 以下是该页面的代码;

   <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ForSale.aspx.vb" Inherits="Users_ForSale" title="Properties For Sale" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


    <h3>Properties For Sale</h3>
    <h5>
        <asp:Label ID="lblTown" runat="server" Text="Town:"></asp:Label>
        <asp:DropDownList ID="ddlTownSearch" runat="server">
            <asp:ListItem></asp:ListItem>
            <asp:ListItem>Chadderton</asp:ListItem>
            <asp:ListItem Value="Failsworth"></asp:ListItem>
            <asp:ListItem>Oldham</asp:ListItem>
            <asp:ListItem>Royton</asp:ListItem>
            <asp:ListItem>Shaw</asp:ListItem>
        </asp:DropDownList>
        <asp:Label ID="lblBedroomsSearch" runat="server" Text="Bedrooms:"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem></asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem Value="2"></asp:ListItem>
            <asp:ListItem Value="3"></asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            <asp:ListItem>6+</asp:ListItem>
        </asp:DropDownList>
        <asp:Label ID="lblMinPrice" runat="server" Text="Min Price (£):"></asp:Label>
        <asp:TextBox ID="txtMinPriceSearch" runat="server" Width="87px"></asp:TextBox>
        <asp:Label ID="lblMaxPriceSearch" runat="server" style="text-align: left" 
            Text="Max Price (£):"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="87px"></asp:TextBox>
    </h5>
    <h5>
        <asp:Button ID="btnForsaleSearch" runat="server" Text="Search" />
    </h5>
    <p>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
            DataKeyNames="ProductId" DataSourceID="SqlDataSource1" ForeColor="#333333" 
            GridLines="None" Width="588px">
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <Columns>
                <asp:ImageField DataImageUrlField="ImageURL">
                </asp:ImageField>
                <asp:BoundField DataField="ProductId" HeaderText="ProductId" ReadOnly="True" 
                    SortExpression="ProductId" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                <asp:BoundField DataField="Town" HeaderText="Town" 
                    SortExpression="Town" />
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </p>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:JPEstatesConnectionString %>" 
    SelectCommand="SELECT * FROM [Products]" 
        DeleteCommand="DELETE FROM [Products] WHERE [ProductId] = @ProductId" 
        InsertCommand="INSERT INTO [Products] ([ProductId], [Description], [Price], [Category], [ImageURL]) VALUES (@ProductId, @Description, @Price, @Category, @ImageURL)" 
        UpdateCommand="UPDATE [Products] SET [Description] = @Description, [Price] = @Price, [Category] = @Category, [ImageURL] = @ImageURL WHERE [ProductId] = @ProductId">
            <DeleteParameters>
                <asp:Parameter Name="ProductId" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Category" Type="String" />
                <asp:Parameter Name="ImageURL" Type="String" />
                <asp:Parameter Name="ProductId" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ProductId" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price" Type="Decimal" />
                <asp:Parameter Name="Category" Type="String" />
                <asp:Parameter Name="ImageURL" Type="String" />
            </InsertParameters>
    </asp:SqlDataSource>

</asp:Content>

It depends on your strategy, if you want to search with EXACTLY same matches your search query will be like this: SELECT * FROM [Products] WHERE [ProductId]=@ProductID AND [Price]=@Price AND ...and other conditions that you need. 这取决于您的策略,如果您要使用完全相同的匹配项进行搜索,则搜索查询将像这样: SELECT * FROM [Products] WHERE [ProductId]=@ProductID AND [Price]=@Price AND ...以及其他条件您需要的。

and if you like to retrieve similar results you have to use LIKE instead of '=' like this one: SELECT * FROM [Products] WHERE [ProductId] LIKE '%' + @ProductId+ '%' AND ([Price] BETWEEN @Price1 AND @Price2) AND ...and other conditions 如果您想检索类似的结果,则必须使用LIKE而不是'=',例如: SELECT * FROM [Products] WHERE [ProductId] LIKE '%' + @ProductId+ '%' AND ([Price] BETWEEN @Price1 AND @Price2) AND ...以及其他条件

Price1 and Price2 can be range of user input price Price1和Price2可以是用户输入价格的范围

It helps you for using ASP.NET SQLParameters with LIKE statement 它可以帮助您通过LIKE语句使用ASP.NET SQLParameters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM