private void loginButton_Click(object sender, EventArgs e) { string userName = usernameTextBox.Text.ToString(); string password = passwordTextBox.Text.ToString(); int successSwitch = 0; using (MySqlConnection mySqlCon = new MySqlConnection(connectionString)) { mySqlCon.Open(); MySqlCommand cmd = new MySqlCommand("SELECT U04pXF.user.userName," + " U04pXF.user.password FROM U04pXF.user", mySqlCon); MySqlDataAdapter mySqlDA = new MySqlDataAdapter(cmd); DataTable dtbl = new DataTable(); mySqlDA.Fill(dtbl); foreach (DataRow dr in dtbl.Rows) { string userFetched = dr["userName"].ToString(); string passwordFetched = dr["password"].ToString(); if (userName == userFetched && password == passwordFetched) { successSwitch = 1; CurrentUser = userFetched; DateTime x = new DateTime(); x = DateTime.Now; LoginTime = x.ToString(); LogEntry(); } } } if (successSwitch == 1) { MainScreen mainScreen = new MainScreen(); mainScreen.Show(); this.Hide(); } else { errorLabel.Visible = true; } }