I have a small program that queries a database and retrieve some information about employees. The only problem I have is that when I search for the employee my program never finds any employee after the first employee.
Here is my code:
private void buttonSearch_Click(object sender, EventArgs e)
{
string sname = textBoxNameIN.Text;
string slname = textBoxSNameIN.Text;
string name;
string lname;
string gender;
string id;
string province;
string city;
string addr;
string field;
string degree;
try
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\Databases\employeedb.accdb");
conn.Open();
OleDbCommand cmd = new OleDbCommand("select * from Employee", conn);
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
name = reader["fname"].ToString();
lname = reader["lname"].ToString();
gender = reader["gender"].ToString();
id = reader["iden"].ToString();
province = reader["province"].ToString();
city = reader["city"].ToString();
addr = reader["addr"].ToString();
field = reader["field"].ToString();
degree = reader["degree"].ToString();
if ((name == sname) && (lname == slname))
{
textBoxNameOut.Text = name;
textBoxLNameOut.Text = lname;
textBoxGenderOut.Text = gender;
textBoxIDOut.Text = id;
textBoxProvinceOut.Text = province;
textBoxCityOut.Text = city;
textBoxAddrOut.Text = addr;
textBoxFieldOut.Text = field;
textBoxDegreeOut.Text = degree;
break;
}
else
{
MessageBox.Show("Could not find the employee you are looking for.");
break;
}
}
conn.Close();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message.ToString());
}
}
How do I fix this?