954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error when logging in

hi. i have a main form and log-in form. when i try to log-in and entered a wrong user or password it gives me error and i dont understand why the error is in the main form??? heres my code in my login form..

private void Lgbtn_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=C:\Users\BHELLE\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\PDG.mdb");
            OleDbCommand cmd = new OleDbCommand("SELECT Users.username, Users.password,Users.start_date, userprof.username, userprof.firstname, userprof.lastname, userprof.weight, userprof.height, userprof.age, userprof.BMI,userprof.gender,userprof.illness1,userprof.illness2,userprof.classification,userprof.weeklydate FROM Users, userprof where userprof.weeklydate= (SELECT MAX(weeklydate) FROM userprof WHERE  Users.username=userprof.username)", conn);


            OleDbDataReader reader;
            bool permit = false;
           
          
            try
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    if (textBox1.Text == (reader["Users.username"].ToString()) && textBox2.Text == reader["password"].ToString())
                    {
                        GlobalClass1.globalage = reader["age"].ToString();
                        GlobalClass1.globaluser = reader["Users.username"].ToString();
                        GlobalClass1.globalBMI = reader["BMI"].ToString();
                        GlobalClass1.globalclas = reader["classification"].ToString();
                        GlobalClass1.globalfnam = reader["firstname"].ToString();
                        GlobalClass1.globallname = reader["lastname"].ToString();
                        GlobalClass1.globalgen = reader["gender"].ToString();
                        GlobalClass1.globaldate = reader["start_date"].ToString();
                        GlobalClass1.globalill1 = reader["illness1"].ToString();
                        GlobalClass1.globalweekdt = reader["weeklydate"].ToString();



                        permit = true;

                        break;
                    }
                    //conn.Close();
                   
                }
            }



            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (permit == true)
            {
                
                this.Close();
                MessageBox.Show("access granted");

                (this.Owner as Main).logoutToolStripMenuItem.Enabled = true;
                (this.Owner as Main).loginToolStripMenuItem.Enabled = false;
                (this.Owner as Main).homebtn.Enabled = true;
                (this.Owner as Main).Pdgbtn.Enabled = true;
                (this.Owner as Main).Infobtn.Enabled = true;
                (this.Owner as Main).Exitbtn.Enabled = true;
                (this.Owner as Main).newUserToolStripMenuItem.Enabled = false;
                
            }
           
            
            else
            {
                MessageBox.Show("access denied");
                textBox1.Text = "";
                textBox2.Text = "";

            }

           if  (DateTime.Now.Date > Convert.ToDateTime(GlobalClass1.globalweekdt))//tried to remove this but still had error
            {
                MessageBox.Show("A WEEK HAVE PASSED, PLEASE UPDATE YOUR PROFILE");
                

            }
           



        }

then when entered a wrong user or password this occur.. see picture..
can someone explain me the error? THANKS

Attachments error.png 229.56KB
kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

What type is this GlobalClass1.globaldate = reader["start_date"].ToString(); ?

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 
What type is this GlobalClass1.globaldate = reader["start_date"].ToString(); ?


its a global variable.. i use it in all my subforms.. its values are from my database.

kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

What TYPE is it. String? DateTime? Int32?

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 
What TYPE is it. String? DateTime? Int32?


A String... :v:)

kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

You did not say whay the error is?
What is the error message and on what line does it occur?

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 
You did not say whay the error is? What is the error message and on what line does it occur?


the error is in the attached picture:)

kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Sorry, did not see that.
But it still does not show where the error occurs in the code snippet you posted.
Is the error captured by the catch in line 44?
Does the "access denied" message appear?
Where does the exception occur when you have Exceptions set to when thrown?
(Debug - Exceptions - "Common Language Runtime Exceptions" check Thrown.)
(Don't forget to un-check this or it will become a pest when testing your own exception handling.)

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 
Sorry, did not see that. But it still does not show where the error occurs in the code snippet you posted. Is the error captured by the catch in line 44? Does the "access denied" message appear? Where does the exception occur when you have Exceptions set to when thrown? (Debug - Exceptions - "Common Language Runtime Exceptions" check Thrown.) (Don't forget to un-check this or it will become a pest when testing your own exception handling.)


yeah thats my problem, it didnt tell where the error occurs, it only happens when i entered a wrong user or pass.

kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

So line 44 is not catching the exception?

Try setting the debugger to break when the exception is thrown (First chance exception!).
Debug - Exceptions - "Common Language Runtime Exceptions" - check the Thrown column.
Then test again. Hopefully it will break at a different line.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

i get it now.. thanks.. the problem is when i entered a wrong pass or user, the if statement still executes. THANKS.

kapojian
Junior Poster in Training
52 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You