Help Adding a Login Form 7 posts

OP Wed Jul 25, 2018 6:25 pm
User avatar
Little
Inner Family Member
  • Gender: Female
  • Posts: 340
  • Joined: Mar, 2018
  • Advertisements: 6
  • Karma: 33
Hi. I created a windows forms application with c# and I wanted to add a login. I created a login on a separate program and imported it to the main app but I couldnt figure out how to call the main app after my login successful.
Code
private void btnLogin_Click(object sender, EventArgs e)
        {
            dsUsers.ReadXml(XMLlocation);
            for (int i = 0; i < dsUsers.Tables["LoginUsers"].Rows.Count; i++)
            {
                USerID = dsUsers.Tables["LoginUsers"].Rows[i]["UserId"].ToString();
                Password = dsUsers.Tables["LoginUsers"].Rows[i]["PAssword"].ToString();
                if(txtBxUserID.Text == USerID && txtBxPassword.Text==Password)
                {
                    LoginSuccess = true;
                    this.Hide();
                   

                }

            }
            if (LoginSuccess==true)
            {
                MessageBox.Show("Login Successful"); //I removed this here and wanted to add a line below this ro run new form1. I cant recall the code I typed now. 
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }


I ended up with one solution and two forms and tried this code again but it still said i needed a using statement. I got tired after hours of trying and screwing up my app. I ended up having to recreate from scratch. This is actually something I'm going to donate to a non profit church group. Just a basic app they need but I want it to look nice.

Right now, I deleted the login and I want to know if anyone has any advice on how to go about adding it in.

Thank you.
Wed Jul 25, 2018 6:35 pm
User avatar
Administrator
Legendary Family Member
  • Gender: Male
  • Posts: 6284
  • Joined: Jun, 2010
  • Advertisements: 45
  • Karma: 368
Import your Form.cs and Form.Designer.cs file into your solution. Then replace the namespace in the two files. Finally, in your main form.cs file create a new instance of the new form then you can access the methods and properties of it.
OP Wed Jul 25, 2018 6:42 pm
User avatar
Little
Inner Family Member
  • Gender: Female
  • Posts: 340
  • Joined: Mar, 2018
  • Advertisements: 6
  • Karma: 33
Why do I need to Rename?
Wed Jul 25, 2018 7:05 pm
User avatar
Administrator
Legendary Family Member
  • Gender: Male
  • Posts: 6284
  • Joined: Jun, 2010
  • Advertisements: 45
  • Karma: 368
Because the namespace needs to match across all your files in the solution. Unless you have separate solutions in one project in which case you need to reference your solutions via using statements.
OP Wed Jul 25, 2018 7:11 pm
User avatar
Little
Inner Family Member
  • Gender: Female
  • Posts: 340
  • Joined: Mar, 2018
  • Advertisements: 6
  • Karma: 33
ok... so right now I have two completely separate files because I restarted the login. Do I import it by adding existing project? thats what i did last time. was that part correct or is there a better way? this will import the entire project and then I added it to the solution from there but the code got all mixed up. my memos code was in the main app and it ended up inside the login app. screwed up everything until i found it and deleted it.
Wed Jul 25, 2018 7:20 pm
User avatar
Administrator
Legendary Family Member
  • Gender: Male
  • Posts: 6284
  • Joined: Jun, 2010
  • Advertisements: 45
  • Karma: 368
I would simply take the 2 files and and drag them into your solution and rename the namespaces like I mentioned before. You don't need the entire solution to add a second form.
OP Wed Jul 25, 2018 11:53 pm
User avatar
Little
Inner Family Member
  • Gender: Female
  • Posts: 340
  • Joined: Mar, 2018
  • Advertisements: 6
  • Karma: 33
You are AMAZING!! it's finally finished and it's got a login :dancingbannana: Thank you for all the help :awesome14:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT