ฉันกำลังพยายามใช้คุณสมบัติการเปลี่ยนรหัสผ่าน แต่ดูเหมือนว่าจะไม่ทำงาน
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"))
{
DataTable dt = new DataTable();
con.Open();
errorProvider1.Clear();
if (dt.Rows[0][0].ToString() == "1")
{
if (textBox3.Text == textBox4.Text)
{
OleDbDataAdapter da = new OleDbDataAdapter(" COUNT (*) FROM login WHERE username= '" + textBox1.Text + "' AND [password]='" + textBox2.Text + "' ", con);
OleDbCommand com = new OleDbCommand("UPDATE login SET [password] = '" + textBox3.Text + "' WHERE username = '" + textBox2.Text + "'", con);
com.ExecuteNonQuery();
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");
}
}
}
มีข้อผิดพลาดในบรรทัด if (dt.Rows[0][0].ToString() == "1")
โดยระบุว่าไม่พบข้อมูลในตำแหน่งนั้น แต่มี 5 แถวในตารางข้อมูล
เมื่อโค้ดถูกรันโดยไม่มีบรรทัดด้านบน เช่น //if (dt.Rows[0][0].ToString() == "1")
รหัสทำงาน แต่ไม่มีการอัปเดตข้อมูลในตาราง
อัปเดตรหัสอีกครั้งและยังคงได้รับข้อผิดพลาดเดิม:
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM login WHERE username= '" + textBox1.Text + "' AND [password]='" + textBox2.Text + "' ", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Open();
errorProvider1.Clear();
if (dt.Rows[0][0].ToString() == "1")
DataTable
โดยไม่ต้องกำหนดข้อมูลใดๆ ให้กับมัน! - person Salah Akbari   schedule 07.01.2016