Log In Form

hi there , in my App i made a Form that u log into the App whit .
the code is :

SqlCommand cmd1 = new SqlCommand();
                  SqlParameter parm = new SqlParameter("@parm",SqlDbType.VarChar,50,"Pass");
                  cmd1.CommandText = "select @parm = Pass from Bakara";
                  string Password = parm.Value.ToString();
                  if(Password == this.editBox1.Text)
                        MessageBox.Show("The Pass Is False try Agian");
                  if (i==3)
                        MessageBox.Show("Incoorect 3 time Piss Off");

now if the user close the form the app is still working whitout the login was verified to be true .
what can i do to overpower this problem ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use the event the app throws when it closes and put the text you need to close the connection on it
there're really several approaches, some of them:

your login form could be the application main form (my preference) - in other words, that's the one with the Main() function in it, in which case if you close this form, the whole application is closed.

another way is you can just add OnClosing event handler for your login form and from there you can call some public function from your current main form which would call this.Close(); of your main form - it will close your main application

if you WANT your user be able to see your application without logging but not be able to do anything, you can set a parameter parameter of your main application from your login form to true or false depending on the login situation and check for this parameter in your application form (in the form load method), then you can diable controls for example and show big message across your form - log in first please.

good luck,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Set the DialogResult property of the login form before you exit.  Then you can check this back in the calling form to test whether or not login was successful and exit the application if appropriate.

(When the close button is clicked on a modal form the DialogResult is set to Cancel for you)

Simplified example:

            Form1 f1 = new Form1();
            if (f1.ShowDialog() != DialogResult.OK)

            // continue with your app...

    public partial class Form1 : Form

        private void button1_Click_1(object sender, EventArgs e)
            // set the DialogResult based on the results
            if (true)
                this.DialogResult = DialogResult.OK;
                this.DialogResult = DialogResult.Cancel;

Here is my solution:

 static void Main(string[] args)
               LoginForm login = new LoginForm();
               if( login.IsOK == true )
                    Application.Run(new MainForm());

IsOK is a property of LoginForm (or public variable). You must set login.IsOK == true if user and password are correct

Good luck,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.