Results 1 to 2 of 2

Thread: how to hide main form before login?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    how to hide main form before login?

    i amd developing windows application using C#. i want to add login form to my project so that i can only see the main form after i successfully loged in.
    so how can i do that. the name of my main form is: hrmainfrm
    my login code is:
    Code:
     private void vblogin_Click(object sender, EventArgs e)
            {
               
                dbcon.Close();
                dbcon.Open();
            string qry;
            SqlDataReader dr;
            qry = "select username,password from userstbl where username='" + txtuserid.Text + "' and password='" + txtpwd.Text + "'";
            SqlCommand cmd = new SqlCommand(qry, dbcon);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
               //what  to do here if login is success
                
            }
            else
            {
             lblerr.Text = "Enter valid UserName/Password";
            }
            dbcon.Close();
        }
    i am beginner please help me

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: how to hide main form before login?

    The main form gets created and displayed in the Main method, which you'll find in the Program.cs file. You simply display your login dialogue there by calling ShowDialog and use the DialogResult it returns to decide whether to display the main form or not. You then don;t need to call Close on the login dialogue. You just set its DialogResult property. Use OK for a successful login and Cancel otherwise.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width