Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       SqlConnection conn = new SqlConnection("Data Source=localhost\\SqlExpress;Initial Catalog=dad1;Integrated Security=True");
       string pass = "pppp", rol = "rrrr", sql;

       sql = "SELECT * FROM UserName where Name ='" + TextBox1.Text + "' ";
       SqlCommand comm = new SqlCommand(sql, conn);
       conn.Open();

       SqlDataReader reader = comm.ExecuteReader(); \\ this is problem
       if (reader.Read())
       {
           pass = (string)reader["password"];
           rol = (string)reader["role"];
       }
       else
       { Label1.Text = "no user found "; }
       reader.Close();
       conn.Close();
       if (TextBox2.Text == pass)
       {
           Session["Authencated"] = rol;
           if (rol == "Admin")
               Server.Transfer("Default2.aspx");
           else
               Server.Transfer("Default3.aspx");
       }
       else
           Label1.Text = "wrong password";

   }
Posted
Comments
Member 11685473 12-May-15 15:49pm    
this is login page
F-ES Sitecore 12-May-15 16:15pm    
Is there an InnerException? What is in Textbox1? Try putting brackets around your tables and fields in your SQL

SELECT * FROM [UserName] where [Name] =

Also, probably nothing to do with your problem but don't use select *, always detail the fields you are returning. And don't construct SQL the way you are as it leaves you open to sql injection attacks, use parameterised queries instead (google for examples on how you use them)
Member 11685473 14-May-15 9:32am    
It's working now .
Thank you
Sascha Lefèvre 12-May-15 16:37pm    
Please tell us the exception message and, if present, name and messages of inner exceptions.
Member 11685473 14-May-15 9:32am    
It's working now .
Thank you

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

  Print Answers RSS


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