Click here to Skip to main content
14,302,017 members
Rate this:
Please Sign up or sign in to vote.
Sir i want to search My Databse based on multiple criteria fill by the user but m not getting how to do that..city name,locality name property type should be same but price and area should be within the range specified by the user...pls help thanks in advance....

Form Design
<div>

           <table cellspacing="15" style="width:80%">
               <tr>
                   <td colspan="2" align="left">
                       <span style="font-size: small; font-family: Arial">Fields marked with
                   </span>
                   <span style="color: #FF3300; font-size: small; font-family: Arial;">*</span><span
                           style="font-size: small; font-family: Arial"> are
                   mandatory:

                   </span>

                   </td>
               </tr>
               <tr>
                   <td colspan="2" align="left">
                       <span style="text-decoration:none">
                       <span style="text-decoration: underline">Search Property For:</span></span><br /><br />
                       <asp:RadioButton ID="rbtnfs" Checked="true" Text="For Sale" GroupName="radio" runat="server" ></asp:RadioButton>

                   <asp:RadioButton ID="rbtnfr" Text="For Rent" GroupName="radio" runat="server" ></asp:RadioButton>
                   <span style="font-size: x-small; font-family: Arial; ">       
                   <span style="text-decoration: underline">Select Atleast One Option</span></span><br />
                  <%-- <asp:Label ID="lblerror" ForeColor="Red" runat="server" Text=""></asp:Label>--%>

                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Keyword :
                   </td>
                   <td style="width: 416px">
                       <asp:TextBox  ID="txtkeyword" runat="server" Width="167px"></asp:TextBox>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Property Type :
                   </span>
                   <span style="color: #FF0000">*</span></td>
                   <td style="width: 416px">
                       <asp:DropDownList ID="ddlpropertytype" runat="server" CssClass="validate[required] radio"
                       Width="169px">
                       <asp:ListItem Value="">--Select--</asp:ListItem>
                       <asp:ListItem Value="Commercial">Commercial</asp:ListItem>
                       <asp:ListItem Value="Residential">Residential</asp:ListItem>
                       <asp:ListItem Value="Plot">Plot</asp:ListItem>
                       <asp:ListItem Value="Bunglow">Bunglow</asp:ListItem>
                       <asp:ListItem Value="Villa">Villa</asp:ListItem>
                   </asp:DropDownList>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">City :
                   </span>
                   <span style="color: #FF0000">*</span></td>
                   <td style="width: 416px"><asp:DropDownList ID="ddlcity" runat="server" Width="169px" CssClass="validate[required] radio">
                           <asp:ListItem Value="">--Select--</asp:ListItem>

                       </asp:DropDownList>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Locality :</span>
                   <span style="color: #FF0000">*</span></td>
                   <td style="width: 416px">
                       <asp:DropDownList ID="ddllocality" runat="server" Width="169px" CssClass="validate[required] radio">
                       <asp:ListItem Value="">--Select--</asp:ListItem>

                       </asp:DropDownList>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Price :
                   </span>
                   <span style="color: #FF0000">*</span></td>
                   <td style="width: 416px">
                       <asp:DropDownList ID="ddlprice" runat="server"
                           CssClass="validate[required] radio" Height="20px" Width="169px">
                       <asp:ListItem Value="">--Select--</asp:ListItem>
                       <asp:ListItem Value="1">5 to  10 Thousand</asp:ListItem>
                       <asp:ListItem Value="2">10 to 25 Thousand</asp:ListItem>
                       <asp:ListItem Value="3">25 to 50 Thousand</asp:ListItem>
                       <asp:ListItem Value="4">50 to 75 Thousand</asp:ListItem>
                       <asp:ListItem Value="5">75 to 85 Thousand</asp:ListItem>
                       <asp:ListItem Value="6">85 to 100 Thousand</asp:ListItem>
                       <asp:ListItem Value="7">1 to 10 Lakhs</asp:ListItem>
                       <asp:ListItem Value="8">10 to 25 Lakhs</asp:ListItem>
                       <asp:ListItem Value="9">25 to 35 Lakhs</asp:ListItem>
                       <asp:ListItem Value="10">35 to 45 Lakhs</asp:ListItem>
                       <asp:ListItem Value="11">45 to 55 Lakhs</asp:ListItem>
                       <asp:ListItem Value="12">55 to 65 Lakhs</asp:ListItem>
                       <asp:ListItem Value="13">65 to 75 lakhs</asp:ListItem>
                       <asp:ListItem Value="14">75 to 85 Lakhs</asp:ListItem>
                       <asp:ListItem Value="15">85 to 100 Lakhs</asp:ListItem>
                        <asp:ListItem Value="15">1 to 1.5 Crores</asp:ListItem>
                         <asp:ListItem Value="15">1.5  to 2 Crores</asp:ListItem>
                          <asp:ListItem Value="15">2 to 2.5 Crores</asp:ListItem>
                         <asp:ListItem Value="15">2.5  to 3 Crores</asp:ListItem>
                          <asp:ListItem Value="15">3 to 5 Crores</asp:ListItem>
                         <asp:ListItem Value="15">5  to 10 Crores</asp:ListItem>
                          <asp:ListItem Value="15">1o to 15 Crores</asp:ListItem>
                         <asp:ListItem Value="15">15  to 25 Crores</asp:ListItem>
                          <asp:ListItem Value="15">25 to 35 Crores</asp:ListItem>
                         <asp:ListItem Value="15">35  to 45 Crores</asp:ListItem>
                          <asp:ListItem Value="15">45 to 55 Crores</asp:ListItem>
                         <asp:ListItem Value="15">55  to 65 Crores</asp:ListItem>
                          <asp:ListItem Value="15">65 to 75 Crores</asp:ListItem>
                         <asp:ListItem Value="15">75  to 85 Crores</asp:ListItem>
                         <asp:ListItem Value="15">85  to 100 Crores</asp:ListItem>

                   </asp:DropDownList>


                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Bedroom :</td>
                   <td style="width: 416px">
                       <asp:DropDownList ID="ddlbedrooms" runat="server"
                       Width="169px">
                       <asp:ListItem Value="">--Select--</asp:ListItem>
                       <asp:ListItem Value="1">0</asp:ListItem>
                       <asp:ListItem Value="2">1</asp:ListItem>
                       <asp:ListItem Value="3">2</asp:ListItem>
                       <asp:ListItem Value="4">3</asp:ListItem>
                       <asp:ListItem Value="5">4</asp:ListItem>
                       <asp:ListItem Value="6">5</asp:ListItem>
                       <asp:ListItem Value="7">6</asp:ListItem>
                       <asp:ListItem Value="8">7</asp:ListItem>
                       <asp:ListItem Value="9">8</asp:ListItem>
                       <asp:ListItem Value="10">9</asp:ListItem>
                       <asp:ListItem Value="11">10</asp:ListItem>


                   </asp:DropDownList>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                       <span style="font-size: small; font-family: Arial">Built Up Area :</span>
                   <span style="color: #FF0000">*</span></td>
                   <td style="width: 416px" height="34px">
                       <asp:TextBox ID="txtminarea" runat="server" Height="18px" Width="53px" CssClass="validate[required,custom[number]]"></asp:TextBox>
                        
                       <asp:TextBox ID="txtmaxarea" runat="server" Height="18px" Width="52px" CssClass="validate[required,custom[number]]"></asp:TextBox>
                         
                       <asp:DropDownList ID="ddlarea" runat="server" CssClass="validate[required] radio">
                       <asp:ListItem Value="">--Select--</asp:ListItem>
                       <asp:ListItem Value="fe">sqft</asp:ListItem>
                       <asp:ListItem Value="me">sqm</asp:ListItem>
                       <asp:ListItem Value="ya">sqyds</asp:ListItem>

                       </asp:DropDownList>
                   </td>
               </tr>
               <tr>
                   <td style="width: 125px">
                        
                   </td>
                   <td style="width: 416px">
                       <asp:Button class="btn" ID="btnSubmit" runat="server" Text="Search" Width="75px"
                           onclick="btnSubmit_Click" />
                    <asp:Button class="btn" ID="btnreset" runat="server" Text="Reset"
                           UseSubmitBehavior="false" Width="75px" onclick="btnreset_Click"/>
                   </td>
               </tr>
           </table>
       </div>
Posted
Updated 3-Oct-12 0:16am
v2
Comments
Tejas Vaishnav 3-Oct-12 6:29am
   
what your problem, we can not figure out by seeing your design code, that you have this problem. so if you have tried any thing then please put that thing not your design.
Raj.Rautela 3-Oct-12 7:21am
   
hey hello Tejas sir i'hv pasted my dought look at this query pls help..
Raj.Rautela 3-Oct-12 6:52am
   
SqlConnection con = new SqlConnection(str);
string strQ = ("Select P_ID, Property_Type,City_Name,Locality_Name,Price,Build_up_area,Bedrooms,Property_Image From tbl_post_property_sale,tbl_City,tbl_Locality where tbl_post_property_sale.City_Id=tbl_City.City_Id and tbl_post_property_sale.locality_Id=tbl_Locality.locality_Id and Property_Type like '" + ddlpropertytype.SelectedItem.Text + "',City_Name like '" + ddlcity.SelectedItem.Text + "',Locality_Name like '" + ddllocality.SelectedItem.Text + "'Bedrooms like '" + ddlbedrooms.SelectedItem.Text + "' and Price between '" + ddlprice.SelectedItem.Text + "'");
SqlCommand cmdsearch = new SqlCommand(strQ, con);
con.Open();
cmdsearch.ExecuteNonQuery();
con.Close();

m writing this query to search but not getting any output something is wrong in price range..

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Run the solution in DEBUG mode, put a break point at SqlCommand and check how the query looks like.
Copy the value of strQ variable, and execute in SQL management studio or in Visual Studio and see where the error is.
It is next to impossible for us to debug your SQL query. From the initial looks for me it looks like there is an error in the Between clause that you are using.
Between clause expects Value1 AND Value2, where as your query is passing something similar between '75 to 85 lakhs'.
   
Comments
Raj.Rautela 3-Oct-12 8:27am
   
sir i want to find a property from database whose price range is between 75 to 85 lakhs..whatever u told i'hv done that the error is at price column m not getting how to find property by price range..
Raj.Rautela 3-Oct-12 8:30am
   
m having a property in my databse whose price is 80 lakhs and i want to display that proerty bcoz it is in the range of 75 to 85...but not getting the logic how to get that...everything else is working proper but price column is having prblm...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100