I am trying to create log in system with access database in c#. I have a database, and User_ID and Password Columns, I don't know why it doesn't work, can you help me with your opinion? The problem is that program checks only 1st user, but when I enter 3rd or 4th user, it displays message: your username or password is incorrect even though user_ID and password is correct. here is the code:
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection connect = new OleDbConnection();
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Hodzic\Desktop\projekat shipping\Database files\Users.accdb";
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "select User_ID, Password from user_details";
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
if (textBox1.Text == reader[0].ToString() && textBox2.Text == reader[1].ToString())
{
this.Hide();
Glavna2 g1 = new Glavna2();
g1.Show();
break;
}
else
{
MessageBox.Show("Your user ID or password is incorrect.");
this.Hide();
Sign_in g2 = new Sign_in();
g2.Show();
break;
}
}
connect.Close();
}
Thank you.