locked
errors in login page RRS feed

  • Question

  • User399028669 posted

    this is the code  i have written for my login page.

    the errors are at the bottem. i've only started using asp.net and cant fix the errors.

     

    rotected void LoginButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
              
                    string username = Username.Text; //Get the username from the control
                    string password = Password.Text; //get the Password from the control

                    SqlCommand comm;
                    SqlConnection conn;
                    SqlDataAdapter dataAdapter;
                    SqlDataReader dataReader;
                  
                    string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
                    comm = new SqlCommand("select Username, Password from tblEmployee where Username =" + username + "‘ AND Password =’" + password, conn);
                    DataSet userDS = new DataSet();

                  
                  

                  
                       conn = new SqlConnection(connectionString);
                       conn.Open();
                       // execute the command
                      // dataReader = new SqlDataReader( conn);


                       dataReader = comm.ExecuteReader();
                    //Get the first row and check the password.
                   while (dataReader.Read())
                   {
                       if (dataReader["password"].ToString() == password)
                      
                              Response.Redirect("Employee_Details.aspx");
                       /*else
                       {
                           dbError.Text = "Invalid password.";
                       }*/
                      
                   }
                   /*else
                   {
                       dbErrorMessage.Text = "Login name not found.";
                   }*/
                  dataReader.Close();

                  conn.Close();

                  // Enclose database code in Try-Catch-Finally
                  /*try
                  {
                      // Open the connection
                      conn.Open();
                      // Execute the command
                      comm.ExecuteNonQuery();

                      // Reload page if the query executed successfully
                      Response.Redirect("Employee_Details.aspx");

     

                  }
                  catch
                  {
                      // Display error message
                      dbErrorMessage.Text =
                      "Error submitting employee details! Please " +
                      "try again later, and/or change the entered data!";
                  }
                  finally
                  {
                      // Close the connection
                      conn.Close();
                  }*/
                  
            }

     

    Error 3 Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox' E:\Documents and Settings\student\Desktop\IES\Employee_Details.aspx 1 
    Error 4 The name 'Username' does not exist in the current context E:\Documents and Settings\student\Desktop\IES\Login.aspx.cs 28 35 E:\...\IES\
    Error 5 The name 'Password' does not exist in the current context E:\Documents and Settings\student\Desktop\IES\Login.aspx.cs 29 35 E:\...\IES\
    Error 6 The name 'dbError' does not exist in the current context E:\Documents and Settings\student\Desktop\IES\Employee_Details.aspx.cs 158 21 E:\...\IES\

    Wednesday, May 20, 2009 10:51 AM

All replies

  • User-1597966988 posted

                    string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
                    comm = new SqlCommand("select Username, Password from tblEmployee where Username =" + username + "‘ AND Password =’" + password, conn);
    First! Use parammeters!!! Concat string in query is evil! Error 4-5-6 may be mean that you don't add control on forms. Error 3 - You wrote this, for example, MyTextBox= "Hello, world!"; May be use LINQ2SQL? Its very simple!
    Wednesday, May 20, 2009 11:48 AM
  • User555306248 posted

    The name 'Username' does not exist in the current context means the field are not available First try to create the instance of usercontrol then try to use it

    Try this

    TextBox tempTextBox = (TextBox)(Username)
    string username.Text = tempTextBox.Text;

    Wednesday, May 20, 2009 11:31 PM
  • User555306248 posted

    What is the status of your thread, Have you made any further changes to run TTS

    Wednesday, May 27, 2009 10:53 PM
  • User555306248 posted

     Please update the thread status

    Monday, July 27, 2009 10:54 PM
  • User555306248 posted

     Are you able to compile the application

    Tuesday, July 28, 2009 11:03 PM