This function is in a class file, can't get the frmLogin form to hide when a user logins in, the frmMain will open fine though!???
Code:
public void login(string username,string password) { DBConnect(); //Internal DB connection call frmLogin login = new frmLogin(); md5 = new MD5CryptoServiceProvider(); originalBytes = ASCIIEncoding.Default.GetBytes(password); encodedBytes = md5.ComputeHash(originalBytes); QueryString = "SELECT username,password FROM userdat WHERE username='" + username + "'"; command.CommandText = QueryString; try { Reader = command.ExecuteReader(); Reader.Read(); try { if (Reader.GetValue(0).ToString() != null) { if ((username == Reader.GetValue(0).ToString()) && (BitConverter.ToString(encodedBytes) == Reader.GetValue(1).ToString())) { login.Hide(); new frmMain().Show(); } else { MessageBox.Show("Username or password are incorrect.", "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch(MySqlException) { MessageBox.Show("Username is incorrect.", "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (MySqlException ex01) { MessageBox.Show("Error communicating with the database.\nInternal Error Code: x00001\nError Code: "+ex01, "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Error); } DBDisconnect(); //Internal DB close connection call. }
Comment