private void button1_Click(object sender, EventArgs e) { Login userlogin = new Login(); userlogin.Username = tbxUserName.Text; userlogin.Password = tbxPassword.Text; bool result = dbconnect.ck_login(userlogin); if (result == true) { Answer a = new Answer(); a.AnsYes = true; this.Close(); } else { tbxPassword.Clear(); tbxUserName.Clear(); tbxUserName.Focus(); Timer timer1 = new Timer(); timer1.Interval = 5000; tsLoginLabel.Text = ("Login Failed! Please try again"); timer1.Start(); timer1.Tick += new EventHandler(timer1_Tick); return; } } private void timer1_Tick(object sender, EventArgs e) { tsLoginLabel.Text = ("Ready"); timer1.Stop(); return; } }
I have the following Classes: MyConnection, Login, Answer
See Code Below
public bool ck_login(Login ckLogin){bool result = false;try{OleDbDataAdapter dbadapter = new OleDbDataAdapter();DataTable logdt = new DataTable();dbconnect.Open();dbcommand.CommandText = "SELECT * FROM tblUsers WHERE uName=@userName and uPassword=@userPassword";dbcommand.Parameters.AddWithValue("@userName", ckLogin.Username);dbcommand.Parameters.AddWithValue("@userPassword", ckLogin.Password);dbcommand.CommandType = System.Data.CommandType.Text;dbadapter.SelectCommand = dbcommand;dbadapter.Fill(logdt);if (logdt.Rows.Count <= 0){result = false;logdt.Clear();}else{result = true;logdt.Clear();logdt.Dispose();dbconnect.Close();}}catch (Exception ex){System.Windows.Forms.MessageBox.Show(ex.Message);}finally{dbconnect.Close();}return result;
{bool result = false;try{OleDbDataAdapter dbadapter = new OleDbDataAdapter();DataTable logdt = new DataTable();dbconnect.Open();dbcommand.CommandText = "SELECT * FROM tblUsers WHERE uName=@userName and uPassword=@userPassword";dbcommand.Parameters.AddWithValue("@userName", ckLogin.Username);dbcommand.Parameters.AddWithValue("@userPassword", ckLogin.Password);dbcommand.CommandType = System.Data.CommandType.Text;dbadapter.SelectCommand = dbcommand;dbadapter.Fill(logdt);if (logdt.Rows.Count <= 0){result = false;logdt.Clear();}else{result = true;logdt.Clear();logdt.Dispose();dbconnect.Close();}}catch (Exception ex){System.Windows.Forms.MessageBox.Show(ex.Message);}finally{dbconnect.Close();}return result;
class Login { string username; public string Username { get { return username; } set { username = value; } } string password; public string Password { get { return password; } set { password = value; } } }
class Answer { bool ansYes; public bool AnsYes { get { return ansYes; } set { ansYes = value; } } }}