errors in login page

Last post 07-28-2009 11:03 PM by chetan.sarode. 5 replies.

Sort Posts:

  • errors in login page

    05-20-2009, 10:51 AM
    • Member
      point Member
    • bbbccc
    • Member since 05-20-2009, 2:47 PM
    • Posts 2

    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\

  • Re: errors in login page

    05-20-2009, 11:48 AM
    • Member
      30 point Member
    • GraDea
    • Member since 05-18-2009, 7:13 AM
    • Russia
    • Posts 8
    bbbccc:

                    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!
  • Re: errors in login page

    05-20-2009, 11:31 PM

    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;

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: errors in login page

    05-27-2009, 10:53 PM

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

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: errors in login page

    07-27-2009, 10:54 PM

     Please update the thread status

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: errors in login page

    07-28-2009, 11:03 PM

     Are you able to compile the application

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (6 items)