Windows应用程序通过访问2007更改密码的一些解决方案? [英] some solution for change password by windows app through access 2007?
问题描述
我正在尝试为我的登录表单中的更改密码按钮编写代码...我希望用户可以更改他/她的用户名密码。如果你知道任何解决方案我会非常感谢你在这里建议我...
......这个网站我需要 http://www.daniweb.com/software-development/csharp/ threads / 370196 / c-how-to-change-password-from-database-in-c [ ^ ]但它是用sql编写的,我将其转换为access 2007我需要但我仍然不知道问题在哪里...请一些人帮助我...我真的很困惑.....
它的代码转换为OLEDB是在这里我自己做了...
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Data.OleDb;
命名空间 WindowsFormsApplication34
{
public partial class Form2:表单
{
public Form2()
{
InitializeComponent();
}
private void button1_Click( object sender,EventArgs e)
{
OleDbConnection con = new OleDbConnection( Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\Users\\Persian \\Desktop \\ \\\a.accdb跨度>);
con.Open();
string username = label1.Text;
string password = textBox1.Text;
string newpassword = textBox2.Text;
string confirmpassword = textBox3.Text;
string cmdstring = UPDATE log SET newpass = @newpass WHERE user = @ user;
OleDbCommand cmd = new OleDbCommand(cmdstring,con);
cmd.Parameters.AddWithValue( @ newpass,textBox3.Text);
cmd.Parameters.AddWithValue( @ user,label1.Text);
cmd.Parameters.AddWithValue( @ password,textBox1.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
OleDbDataReader r = null ;
r = cmd.ExecuteReader();
while (r.Read())
{
if ((textBox2.Text == r [ newpass]。ToString())&(textBox3 .Text == r [ confpass]。ToString()))
{
MessageBox.Show( pass changed);
}
this .Close();
}
}
}
请帮帮我解决了这个问题...我真的很累!!
很多人
string cmdstring = UPDATE log SET newpass = @newpass WHERE user = @ user;
我在猜你的数据库log表看起来像这样:
[ID] [用户] [密码]
对吗?
如果是这样,你的SQL错了,你需要类似的东西:
string cmdstring = UPDATE log SET password = @newpass WHERE user = @ user;
cmd.Parameters.AddWithValue( @ newpass,textBox3.Text);
cmd.Parameters.AddWithValue( @ user,label1.Text);
cmd.Parameters.AddWithValue( @ password,textBox1.Text); // 这不是必需的!
我猜你没有一个名为newpass的字段,这就是你遇到问题的原因。您正在尝试设置不存在的字段。
检查此处提供的解决方案:
在asp.net,c#,ms-access数据库中更改密码[ ^ ]
然后看看这些:
PasswordRecovery Class [ ^ ]
密码切换代码 [ ^ ]
hi , i ' m trying to write a code for a button "CHANGE PASSWORD " for my log in form ... i want it helps to user to be able to change his/her password for his/her username ... if u know any solution i will be so thankful to suggest me here ...
sth like this website i need http://www.daniweb.com/software-development/csharp/threads/370196/c-how-to-change-password-from-database-in-c[^] but it has written in sql which i convert it into access 2007 which i am in needed but i still don't know where is the problem ... please some one help me ... i really gor confused .....
its code converted to OLEDB is here which i myself done it ...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication34
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Users\\Persian\\Desktop\\a.accdb");
con.Open();
string username = label1.Text;
string password = textBox1.Text;
string newpassword = textBox2.Text;
string confirmpassword = textBox3.Text;
string cmdstring = "UPDATE log SET newpass=@newpass WHERE user=@user";
OleDbCommand cmd = new OleDbCommand(cmdstring,con);
cmd.Parameters.AddWithValue("@newpass", textBox3.Text);
cmd.Parameters.AddWithValue("@user",label1.Text);
cmd.Parameters.AddWithValue("@password", textBox1.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
OleDbDataReader r = null;
r = cmd.ExecuteReader();
while (r.Read())
{
if((textBox2.Text == r["newpass"].ToString()) & (textBox3.Text==r["confpass"].ToString()))
{
MessageBox.Show("pass changed");
}
this.Close();
}
}
}
please help me to solve this problem ... i really got tired !!
many thanx
string cmdstring = "UPDATE log SET newpass=@newpass WHERE user=@user";
I'm guessing your database "log" table looks something like this:
[ID][user][password]
Right?
If so, you have the SQL wrong, you want something like:
string cmdstring = "UPDATE log SET password=@newpass WHERE user=@user"; cmd.Parameters.AddWithValue("@newpass", textBox3.Text); cmd.Parameters.AddWithValue("@user",label1.Text); cmd.Parameters.AddWithValue("@password", textBox1.Text); //this is not needed!
I'm guessing you don't have a field called "newpass" which is why you are having issues. You are trying to set a field that doesn't exist.
Check the solution provided here:
change password in asp.net,c#,ms-access database[^]
Then have a look at these:
PasswordRecovery Class[^]
code for password chnge[^]
这篇关于Windows应用程序通过访问2007更改密码的一些解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!