Hi I have the following coding whereby I am trying to show Properties that have their price within the from and to drop down menus. However it only works well when the from price is set to 0. when I do price from 1000 to 800000, properties within that range are not shown.

SqlConnection con = new SqlConnection(connString);
        con.Open();
        string sql = "SELECT RefNo, Price, Location, Type, Image_Path1 FROM Properties WHERE  Basis = '" + basis.SelectedItem + "'and Location = '" + location.SelectedItem + "'  and Type = '" + type.SelectedItem + "' and Price > '" + from.SelectedItem + "' and Price < '" + to.SelectedItem + "' ";
        SqlCommand cmd = new SqlCommand(sql, con);

        try
        {
            datalist1.DataSource = cmd.ExecuteReader();
            datalist1.DataBind();
            cmd.Connection.Dispose();
            con.Close();
        }

Recommended Answers

All 2 Replies

What type is Price and what values do you have in from.SelectedItem/to.SelectedItem? I'd take a look at what the sql variable looks like before you call ExecuteReader().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.