在asp.net,c#,ms-access数据库中更改密码 [英] change password in asp.net,c#,ms-access database
问题描述
我在ASP.Net,C#,MS-Access数据库中设计了一个更改密码屏幕。我有4个字段:userid,oldpassword,newpassword,确认密码。我写了一些代码但是收到了错误。
错误:类型''System.Data.OleDb.OleDbDataReader''没有定义构造函数
我的代码如下:
I am desiging a change password screen in ASP.Net,C#,MS-Access database. I''m have 4 fields: userid, oldpassword, newpassword, confirm password. I wrote some code but am getting an error.
Error: The type ''System.Data.OleDb.OleDbDataReader'' has no constructors defined
My code is as follows:
try
{
OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["vhgroupconnection"]
.ConnectionString);
myCon.Open();
string userid = txtuserid.Text;
string oldpass = txtoldpass.Text;
string newPass = txtnewpass.Text;
string conPass = txtconfirmpass.Text;
string q = "select user_id,passwd from register where user_id = @userid and passwd = @oldpass";
OleDbCommand cmd = new OleDbCommand(q, myCon);
OleDbDataReader re = new OleDbDataReader();
cmd.Parameters.AddWithValue("@userid", txtuserid.Text);
cmd.Parameters.AddWithValue("@oldpass", txtoldpass.Text);
re = cmd.ExecuteReader();
re.Read();
if (re["user_id"].ToString() != String.Empty && re["passwd"].ToString() != String.Empty)
{
if (newPass.Trim() != conPass.Trim())
{
lblmsg.Text = "New Password and old password does not match";
}
else
{
q = "UPDATE register SET passwd = @newPass WHERE user_id =@userid";
cmd = new OleDbCommand(q, myCon);
cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text);
cmd.Parameters.AddWithValue("@userod", txtuserid.Text);
cmd.Parameters.AddWithValue("@passwd", txtoldpass.Text);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
lblmsg.Text = "Password changed successfully";
}
else
{
lblmsg.Text = "password not changed";
}
}
}
}
catch(Exception ex)
{
throw ex;
}
请帮我解决问题。
Please help me to solve the problem.
推荐答案
您需要删除该行:
You need to delete the line:
OleDbDataReader re = new OleDbDataReader();
因为该类没有构造函数。这正是错误告诉你的。读者通过调用ExecuteReader进行实例化, http://msdn.microsoft.com/ en-us / library / system.data.oledb.oledbdatareader.aspx [ ^ ]
更改:
because that class does not have a constructor. Which is exactly what the error is telling you. The reader is instantiate by calling ExecuteReader, http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.aspx[^]
Change:
re = cmd.ExecuteReader();
to
to
OleDbDataReader re = cmd.ExecuteReader();
您的其他错误是由您的SQL语句引起的。
Your other error is caused by your SQL statement.
"UPDATE register SET passwd = @newPass WHERE user_id =@userid";
您是在添加3个参数,但只在声明中使用2个参数。将其他参数添加到语句中或删除添加其他参数。
Were you are adding 3 parameters but only using 2 in your statement. Either add the other parameter to your statement or get rid of adding the other parameter.
这篇关于在asp.net,c#,ms-access数据库中更改密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!