i am trying to pick a Varchar field (Question) from tblUser where email = session variable ,

it doesn't give error but picks -1 and shows it, why ?

even that column isn't empt for the matching email

code:

String connectionString = "Data Source=COSANOSTRA; MultipleActiveResultSets=true; Initial Catalog=Waleed_orsfinal;Integrated Security=True";

    protected void Page_Load(object sender, EventArgs e)
    {
        String user_Email = Session["Email_Forgot"].ToString();
        SqlConnection con = new SqlConnection(connectionString);
        String query_qstn = "Select question from tblUser where email = '"+user_Email+"'';
        SqlCommand sqlCom = new SqlCommand(query_qstn,con);

        try
        {
            con.Open();
            String qstn = Convert.ToString( sqlCom.ExecuteNonQuery());
            Response.Write(qstn);
        }
        catch (Exception exc) 
        {
            Response.Write("Error:"+ exc.Message);
        }
        finally
        {
            con.Close();
        }

even if i pass static harcoded email instead of variable, it do give me -1 only, Why ?

I don't know what you mean by -1.

done

String qstn = Convert.ToString( sqlCom.ExecuteScalar());

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.