You must Sign In to post a response.
  • Category: .NET

    How to retrieve values from database related to salary range

    i have a table with name employeeand with column salary whch contains values like 10000,20000--------------so on upto----------------------70000
    and i have dropdownlist box with listitems>=10000,>=20000----------------so on upto----------->=70000
    so when i select value for ex >=40000 in dropdownlist and click on submitbutton records >=40000 should come but not coming
    but i have written query like(" select * from employee where salary='"+dropdownlist1.selecteditem.value+"'",con)

    so any body where iam going wrong suggest me any answer or give me examples
  • #761636

    Hi check your where condition for salary you have written equal salary='"+dropdownlist1.selecteditem.value+"'"

    add greater than also.


    Regards
    Sekhar Babu,
    www.aspdotnet-sekhar.blogspot.in

  • #761642

    Hi

    Refer below code

    protected void DropDownList1_TextChanged(object sender, EventArgs e)
    {
    if (cn.State == ConnectionState.Closed)
    try
    {
    cn.Open();
    string s = "select * from empsal where salary" + DropDownList1.SelectedItem.Value + "";
    OleDbDataAdapter da = new OleDbDataAdapter(s, cn);
    DataSet ds = new DataSet();
    da.Fill(ds, "r");
    GridView1.DataSource = ds.Tables["r"];
    GridView1.DataBind();
    }
    catch (Exception ea)
    {
    throw new Exception(ea + "error");

    }
    finally
    {
    cn.Close();
    }
    }


    find the attachments of out put

    Mark the answer if you are satisfied.

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..


    Sridhar Thota.
    Editor: DNS Forum.

    Delete Attachment

  • #761646

    Hello Velidiviram,

    Refer the below code :

    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Admin\Desktop\WebApplication1\WebApplication1\App_Data\Database1.mdf;Integrated Security=True;User Instance=True");


    protected void DropDownList1_TextChanged(object sender, EventArgs e)
    {
    try
    {
    DataTable dt = new DataTable();
    con.Open();
    SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Employee WHERE Emp_Salary" + DropDownList1.SelectedItem.Value + "", con);
    sda.Fill(dt);
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    finally
    {
    con.Close();
    }
    }

    See the attached image file. It's an output of this code.
    Hope this will help you.


    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #761647
    I am not clear about your table details

    1. Is the salary is numerical value. It it is numerical value do not use "'". use the following query

    select * from employee where salary="+dropdownlist1.selecteditem.value,con

    2.Check the condition whether is it "=" or ">="
    3. If the salary is stored as string value use the "Like" operator inspect of using "="

    By Nathan
    Direction is important than speed

  • #761654
    Hi,

    since you are using dropdownlist items like ">=10000", no need to use "=" in where condition in your Query.

    Instead of below line,

    (" select * from employee where salary='"+dropdownlist1.selecteditem.value+"'",con)


    use like below


    (" select * from employee where salary'"+dropdownlist1.selecteditem.value+"'",con)


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments