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

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

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.

What TYPE is it. String? DateTime? Int32?

What TYPE is it. String? DateTime? Int32?

A String... :v:)

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

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:)

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.)

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.