本文介绍了我的c#代码不会更新访问数据库中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好,这是一个名为Forgot password.aspx $的页面上的代码b $ b我需要用户提供他们的电子邮件,以便他们重置密码。 问题是程序运行,但数据库中的记录没有更新,用户只是重定向到登录页面 我做错了什么?请帮忙! protected void save_Password_Click( object sender,EventArgs e) { OleDbConnection connect = new OleDbConnection(); connect.ConnectionString = @ Provider = Microsoft.ACE.OLEDB.12.0; 数据源= C:\Users\Student\Documents\websiteDatabase.accdb; OleDbDataAdapter adapter = new OleDbDataAdapter( SELECT password FROM userInformation where emailAddress =' + p_Email.Text + ',连接); DataTable dt = new DataTable(); adapter.Fill(dt); 如果(dt.Rows.Count.ToString()== 1) { if (tb_newPassword.Text == tb_Confirm.Text) { // 打开连接 connect.Open(); OleDbCommand cmd = connect.CreateCommand(); cmd.CommandText = UPDATE userInformation SET password =' + tb_Confirm.Text + 'WHERE emailAddress =' + p_Email.Text + '; MessageBox.Show( 密码已成功更改! ); Response.Redirect( 登录Page.aspx); // 关闭连接 connect.Close() ; } else { lbl.Text = 密码不匹配!; } } else { lbl.Text = 更改失败,请再试一次; } } 我的尝试: 我试过寻找查询数据库更新语句的其他方法,但我没有找到任何明确的解决方案解决方案 "Hi guys this is code on a page titled Forgot password.aspxI need the user to provide their email, in order for them to reset their password.The problem is the program does run, but the record in the database is not updated, and the user is just redirected to the sign in pageAm I doing something wrong?please help!"protected void save_Password_Click(object sender, EventArgs e) { OleDbConnection connect = new OleDbConnection();connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Student\Documents\websiteDatabase.accdb"; OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT password FROM userInformation where emailAddress = '" + p_Email.Text + "'", connect); DataTable dt = new DataTable(); adapter.Fill(dt); if ( dt.Rows.Count.ToString() == "1"){ if(tb_newPassword.Text == tb_Confirm.Text){ //Opens the connection connect.Open(); OleDbCommand cmd = connect.CreateCommand(); cmd.CommandText = "UPDATE userInformation SET password ='" + tb_Confirm.Text + "' WHERE emailAddress = '" + p_Email.Text + "'"; MessageBox.Show("Password changed successfully!"); Response.Redirect("Sign In Page.aspx"); //Closes the connectionconnect.Close();}else{ lbl.Text = "Passwords do not match!";}}else{ lbl.Text=" Change unsuccessful, please try again";} }What I have tried:I have tried looking for other ways to query the database update statement, but I have not found any clear solutions 解决方案 这篇关于我的c#代码不会更新访问数据库中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 01:20