locked
Problem with my program RRS feed

  • Question

  • User1527256921 posted
    This code is in my button CLick
    What i want to do is retieve the results corresponding to the range for example A user selects the range >=11 and <=10 from the drodown list i want to display the results from my Table EmpCep 
    if my Duration which is the column name in my table lies within this range
    my column is bigint and its giving an exception cannot explicitly convert varchar to bigint where i have underlined 
    WHAT SHOULD I DO 
    ANY SUGGESTIONS ?
    
    
    
    
    
    
    cepyear = "Cep_Year='" + DropDownList3.SelectedValue + "'";
    cepname = "CepName='" + TextBox1.Text + "'";
    if (Session["qry"] != null)


    cepdur = " Duration in " + Session["qry"].ToString();
    else

    cepdur = " Duration= '" + DropDownList1.SelectedValue + "'";

    string query="select * from EmpCep where " + cepyear + " or " + cepname + " or " + cepdur;
    da = new SqlDataAdapter(query,con);

    ds = new DataSet();

    da.Fill(ds);

    Session["myDataset"] = ds;

    Response.Redirect("CepSearchResult.aspx");


    }
    protected void Button10_Click(object sender, EventArgs e)
    {

    }
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (DropDownList1.SelectedIndex == 1)
    {
    p = "Select Duration from EmpCep where Duration <=5";
    }
    else if (DropDownList1.SelectedIndex == 2)
    {
    p = "Select Duration from EmpCep where Duration >=6 And Duration <=10 ";
    }
    else if (DropDownList1.SelectedIndex == 3)
    {
    p = "Select Duration from EmpCep where Duration >=11 And Duration <=15";
    }
    cmd = new SqlCommand(p, con);

    rd = cmd.ExecuteReader();
    string s3 = "(";

    while (rd.Read())
    {

    s3 += "'" + Convert.ToInt32(rd[0].ToString()).ToString();
    s3 += "',";

    }
    //string age1 = Convert.ToString(p);
    con.Close();

    string s4 = s3.Substring(0, s3.Length - 2);
    s4 += "')";
    // query = "Select Name,PIN,Designation,Gender,Group_Name,Post,Cadre,dob as 'Age' from Employee_Temp where dob in " + s2;
    Session["qry1"] = s4;
    }
    
    
    
    
    THANK YOU

    Smile

    Tuesday, June 14, 2011 4:45 AM

Answers

  • User3866881 posted

    Hello:)

    1)Please make sure that your Dropdownlist3.SelectedValue should be type of numeric.

    2)Please debug to see what's the value of "query" in the  string query="select * from EmpCep where " + cepyear + " or " + cepname + " or " + cepdur;
    There's something wrong with the "query" select statement.I'd like to recommand you to paste it into SQL MANAGEMENT STUDIO before you write down here to run you proj with.

    My solution at present is——

    cepdur = " Duration in (" + Session["qry"].ToString()+")";   --We should add a pair of "()" when using IN statement

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 15, 2011 10:31 PM

All replies

  • User1527256921 posted

    SORRY THE RANGE IS >=11 AND <=20

    Tuesday, June 14, 2011 4:47 AM
  • User3866881 posted

    Hello:)

    1)Please make sure that your Dropdownlist3.SelectedValue should be type of numeric.

    2)Please debug to see what's the value of "query" in the  string query="select * from EmpCep where " + cepyear + " or " + cepname + " or " + cepdur;
    There's something wrong with the "query" select statement.I'd like to recommand you to paste it into SQL MANAGEMENT STUDIO before you write down here to run you proj with.

    My solution at present is——

    cepdur = " Duration in (" + Session["qry"].ToString()+")";   --We should add a pair of "()" when using IN statement

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 15, 2011 10:31 PM
  • User1527256921 posted

    hey thanks so much Smile

    there was just one problem Session[qry] named it wrong

    Friday, June 17, 2011 1:40 PM
  • User3866881 posted

    Hello again:)
    Glad to hear that you've found the problem and fixed that!

    ^_^

    Friday, June 17, 2011 9:23 PM