So I'm working on a login form, this is opened from another form to un-hide certain objects.
on my login form I have a button for the Login statement along with a timer for a status bar message.
When I run my debug and start walking through this. my app keeps looping at the timer for some reason.
I think I have found my issue but really don't know how to correct it. It seems that if a false on the username and password combination are issued. It's keeping the data from the previous select statement, even after I close the connection. It is not going and grabbing the new values in the text boxes.
See Code Below
TypeScript
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; } }Code
I have the following Classes: MyConnection, Login, AnswerCode
See Code BelowJava
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 {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;Code
C#
class Login
{ string username; public string Username { get { return username; } set { username = value; } } string password; public string Password { get { return password; } set { password = value; } } }
Code
Code
C#
class Answer
{
bool ansYes;
public bool AnsYes
{
get { return ansYes; }
set { ansYes = value; }
}
}
}
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 27, 2015, 6:59 PM EST
Marcus Dutton29 reputationPosted Dec 27, 2015, 7:02 PM EST
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 27, 2015, 7:26 PM EST
Marcus Dutton29 reputationPosted Dec 27, 2015, 7:35 PM EST
OleDbConnection cn = new OleDbConnection(ConfigurationManager.ConnectionStrings["Schedule.Properties.Settings.ScheduleConnectionString"].ConnectionString); OleDbDataAdapter logadapter; DataTable dt = new DataTable(); logadapter = new OleDbDataAdapter("SELECT * FROM tblUsers WHERE uName='" + tbxUserName.Text + "' and uPassword='" + tbxPassword.Text + "' and Active='Yes'", cn); logadapter.Fill(dt); if (dt.Rows.Count <= 0) { Timer timer1 = new Timer(); timer1.Interval = 5000; tsLoginLabel.Text = ("Login Failed! Please try again"); timer1.Start(); timer1.Tick += new EventHandler(timer1_Tick); tbxPassword.Clear(); tbxUserName.Clear(); tbxUserName.Focus(); dt.Clear(); cn.Close(); }