Im trying to add a change password feature to my program but it keeps pulling up errors. this is the code thats supposed to run when you click on save:
private void button3_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = (@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\User\Desktop\esoft\gym\gym\bin\Debug\Clients.accdb");
OleDbDataAdapter da = new OleDbDataAdapter(" SELECT COUNT(*) FROM login WHERE username='"+textBox1.Text+ "' AND password='" + textBox2.Text + "'",con);
DataTable dt = new DataTable();
con.Open();
errorProvider1.Clear();
if (dt.Rows[0][0].ToString() == "1")
{
if (textBox3.Text == textBox4.Text)
{
OleDbDataAdapter sda = new OleDbDataAdapter("UPDATE login WHERE username ='" + textBox1.Text + "', password='" + textBox2.Text + "' (password ='" + textBox3.Text + "')", con);
sda.Fill(dt);
MessageBox.Show("password successfully changed", "success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
errorProvider1.SetError(textBox3, "passwords dont match");
errorProvider1.SetError(textBox4, "passwords dont match");
}
}
else
{
errorProvider1.SetError(textBox1, "wrong username");
errorProvider1.SetError(textBox2, "wrong pasword");
}
con.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
the main error for now is that when trying to save, it pulls up an error stating that no rows were found at position 3. when changed to [1][5] it pulls up the same error for that position.
i changed the code using your suggestions, yet still get the same error.
private void button3_Click(object sender, EventArgs e)
{
using (OleDbConnection con = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\User\Desktop\esoft\gym\gym\bin\Debug\Clients.accdb"))
{
OleDbDataAdapter da = new OleDbDataAdapter(" ExecuteScalar FROM login WHERE username='" + textBox1.Text + "' AND password='" + textBox2.Text + "'", con);
DataTable dt = new DataTable();
con.Open();
errorProvider1.Clear();
if (dt.Rows[0][0].ToString() == "1")
{
if (textBox3.Text == textBox4.Text)
{
// OleDbDataAdapter sda = new OleDbDataAdapter("UPDATE login SET password ='" + textBox3.Text + "' WHERE username ='" +textBox2.Text+"'");
OleDbCommand com = new OleDbCommand("UPDATE login SET password = '" + textBox3.Text + "' WHERE username = '" +textBox2.Text+"'",con);
com.ExecuteNonQuery();
// sda.Fill(dt);
MessageBox.Show("password successfully changed", "success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
errorProvider1.SetError(textBox3, "passwords dont match");
errorProvider1.SetError(textBox4, "passwords dont match");
}