Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 17-Apr-13 8:02am
v2
Comments
[no name] 17-Apr-13 14:00pm    
OleDbDataReader re = cmd.ExecuteReader();

Reading the documentation helps a lot in these types of situations.
Richard C Bishop 17-Apr-13 14:04pm    
Post that as the answer, it is correct.
[no name] 17-Apr-13 14:16pm    
Done. Thanks.... too much like work :-)
Devendra Dighe 17-Apr-13 14:05pm    
i tried it
but when i debugged the code it showed exception as
ex {"No value given for one or more required parameters."} System.Exception {System.Data.OleDb.OleDbException}
[no name] 17-Apr-13 14:09pm    
The error has absolutely nothing to do with your current question. You are getting that error because you are passing an UPDATE statement with 3 parameters but your statement only makes use of 2.

1 solution

You need to delete the line:
C#
OleDbDataReader re = new OleDbDataReader();

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:
C#
re = cmd.ExecuteReader();

to
C#
OleDbDataReader re = cmd.ExecuteReader();


Your other error is caused by your SQL statement.
SQL
"UPDATE register SET passwd = @newPass WHERE user_id =@userid";

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.
 
Share this answer
 
Comments
Richard C Bishop 17-Apr-13 14:17pm    
That's a two for one. You solved the original issue of the OP which unveiled another and you got that one as well. +5.
[no name] 17-Apr-13 14:23pm    
Thanks
Devendra Dighe 17-Apr-13 15:06pm    
@ThePhantomUpvoter: i changed the code but its now returning else part of the codeing i.e password was not changed its returning count=0
here is my update query
q = "UPDATE register SET passwd = @newPass WHERE user_id =@userid";
cmd = new OleDbCommand(q, myCon);
cmd.Parameters.AddWithValue("@userid", txtuserid.Text);
cmd.Parameters.AddWithValue("@newPasss", txtnewpass.Text);



int count = cmd.ExecuteNonQuery();

if (count > 0)
{
lblmsg.Text = "Password changed successfully";
}
else
{
lblmsg.Text = "password not changed";
}
[no name] 17-Apr-13 16:29pm    
Is user_id an int? Get the actual SQL text from your command object and see if that works directly in your database.
Devendra Dighe 18-Apr-13 10:26am    
No my user_id is not integer its text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900