Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void Button1_Click(object sender, EventArgs e)
    {<pre>String conn = "Data Source = (LocalDB)\\v11.0;AttachDbFilename = C:\\Users\\Abudlkader\\Documents\\My_Site.mdf;Integrated Security = True;Connect Timeout = 30";
        SqlConnection myconn = new SqlConnection(conn);
        myconn.Open();
        String Query = "SELECT ID FROM SH_SignUp_SignIn WHERE E-Mail LIKE" + TextBox2.Text + "'AND Password LIKE'" + TextBox1.Text + "'";
        SqlCommand mycomm = new SqlCommand();
        mycomm.Connection = myconn;
        mycomm.CommandText = Query;
        int x = Convert.ToInt16(mycomm.ExecuteScalar());
        if (x == null)
        {
            Response.Redirect("~//Default5.aspx");
        }
        else
        {
            Response.Redirect("~//Default4.aspx");
        }
        myconn.Close();
    }
}</pre>
Posted

This:
C#
String Query = "SELECT ID FROM SH_SignUp_SignIn WHERE E-Mail LIKE" + TextBox2.Text + "'AND Password LIKE'" + TextBox1.Text + "'";

is going to:
SQL
SELECT ID FROM SH_SignUp_SignIn WHERE E-Mail LIKETextBox2_Text'AND Password LIKE'TextBox1_Text'

and should be:
SQL
SELECT ID FROM SH_SignUp_SignIn WHERE E-Mail = 'TextBox2_Text' AND Password = 'TextBox1_Text'


Got it?
 
Share this answer
 
Change
int x = Convert.ToInt16(mycomm.ExecuteScalar());
to
object x = mycomm.ExecuteScalar();
 
Share this answer
 
you can change int x to some string variable as you are using int to just check whether some ID exists in DB or not. try using like this:
C#
string x = Convert.ToString(mycomm.ExecuteScalar());
        if (x == DBNull.Value)
        {
            Response.Redirect("~//Default5.aspx");
        }
        else
        {
            Response.Redirect("~//Default4.aspx");
        }

Hope this helps.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900