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